Skip to content

Improve type narrowing for walrus operator in conditional statements#11202

Merged
hauntsaninja merged 1 commit into
python:masterfrom
hauntsaninja:walrus2
Sep 27, 2021
Merged

Improve type narrowing for walrus operator in conditional statements#11202
hauntsaninja merged 1 commit into
python:masterfrom
hauntsaninja:walrus2

Conversation

@hauntsaninja

Copy link
Copy Markdown
Collaborator

Authored by @kprzybyla in #9288. Helps with issue mentioned in #9229.

I fixed some nits and tests, but Github didn't like it when I tried to push to the original branch, so opening a new PR.

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

aioredis (https://github.com/aio-libs/aioredis.git)
- aioredis/client.py:3756: error: Argument 1 to "append" of "list" has incompatible type "Union[bytes, memoryview, str, int, float, None]"; expected "Union[Union[bytes, memoryview], Union[str, int, float]]"
- aioredis/client.py:3771: error: List item 1 has incompatible type "Union[bytes, memoryview, str, int, float, None]"; expected "Union[bytes, str, float]"
- aioredis/client.py:3785: error: List item 1 has incompatible type "Union[bytes, memoryview, str, int, float, None]"; expected "Union[bytes, str, float]"
- aioredis/client.py:3788: error: List item 1 has incompatible type "Union[bytes, memoryview, str, int, float, None]"; expected "Union[bytes, str, float]"

rich (https://github.com/willmcgugan/rich.git)
+ rich/text.py:559: error: Right operand of "or" is never evaluated
+ rich/text.py:563: error: Right operand of "or" is never evaluated
+ rich/text.py:1068: error: Right operand of "or" is never evaluated
+ rich/text.py:1070: error: Right operand of "or" is never evaluated

@hauntsaninja

Copy link
Copy Markdown
Collaborator Author

Going ahead and merging, since all feedback in the original PR has been addressed. The mypy_primer changes all look correct to me (and seem to be the result of the new fallback case for type maps).

@hauntsaninja hauntsaninja merged commit 8e82171 into python:master Sep 27, 2021
@hauntsaninja hauntsaninja deleted the walrus2 branch September 27, 2021 01:11
@hauntsaninja

Copy link
Copy Markdown
Collaborator Author

Thank you for this, kprzybyla!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant