-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Narrow falsey str/bytes/int to literal type #17818
Narrow falsey str/bytes/int to literal type #17818
Conversation
This is consistent with how pyright applies narrowing: Pyright playground |
This comment has been minimized.
This comment has been minimized.
Looked through the primer results:
|
Thanks for the analysis! I agree with your assessment. Re: the false positives from |
Diff from mypy_primer, showing the effect of this PR on open source code: urllib3 (https://github.com/urllib3/urllib3)
+ test/test_response.py:179: error: Non-overlapping equality check (left operand type: "Literal[b'', ''] | None", right operand type: "Literal[b'foo']") [comparison-overlap]
packaging (https://github.com/pypa/packaging)
+ src/packaging/version.py:496: error: Left operand of "and" is always true [redundant-expr]
core (https://github.com/home-assistant/core)
+ homeassistant/components/vlc_telnet/media_player.py:181: error: Right operand of "and" is never evaluated [unreachable]
+ homeassistant/components/vlc_telnet/media_player.py:184: error: Statement is unreachable [unreachable]
prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/_internal/schemas/validators.py:820: error: Incompatible return value type (got "str", expected "Path") [return-value]
+ src/prefect/_internal/schemas/validators.py:820: error: Incompatible return value type (got "Literal['']", expected "Path") [return-value]
- src/prefect/deployments/runner.py:912: error: Item "str" of "str | DockerImage" has no attribute "reference" [union-attr]
- src/prefect/deployments/runner.py:917: error: Item "str" of "str | DockerImage" has no attribute "build" [union-attr]
- src/prefect/deployments/runner.py:921: error: Item "str" of "str | DockerImage" has no attribute "reference" [union-attr]
- src/prefect/deployments/runner.py:933: error: Item "str" of "str | DockerImage" has no attribute "push" [union-attr]
- src/prefect/deployments/runner.py:937: error: Item "str" of "str | DockerImage" has no attribute "reference" [union-attr]
- src/prefect/deployments/runner.py:941: error: Item "str" of "str | DockerImage" has no attribute "reference" [union-attr]
kornia (https://github.com/kornia/kornia)
+ kornia/contrib/extract_patches.py:390: error: Unused "type: ignore" comment [unused-ignore]
+ kornia/contrib/extract_patches.py:395: error: Unused "type: ignore" comment [unused-ignore]
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thank you!
Closes #16891
Before
After