Narrow falsey str/bytes/int to literal type - #17818
Merged
hauntsaninja merged 3 commits intoSep 26, 2024
Merged
Conversation
Collaborator
Author
|
This is consistent with how pyright applies narrowing: Pyright playground |
This comment has been minimized.
This comment has been minimized.
Contributor
|
Looked through the primer results:
|
Collaborator
Author
|
Thanks for the analysis! I agree with your assessment. Re: the false positives from |
Contributor
|
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]
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #16891
Before
After