Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.1k
Narrow falsey str/bytes/int to literal type#17818
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 ourterms of service andprivacy 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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
brianschubert commentedSep 24, 2024
This is consistent with how pyright applies narrowing:Pyright playground |
This comment has been minimized.
This comment has been minimized.
TeamSpen210 commentedSep 24, 2024
Looked through the primer results:
|
brianschubert commentedSep 24, 2024
Thanks for the analysis! I agree with your assessment. Re: the false positives from |
Diff frommypy_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] |
hauntsaninja left a comment
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