Skip to content

Improve type narrowing for walrus operator in conditional statements #11202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2021

Conversation

hauntsaninja
Copy link
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
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
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
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