Fix missing meet case exposed by len narrowing#16470
Merged
hauntsaninja merged 1 commit intopython:masterfrom Nov 12, 2023
Merged
Fix missing meet case exposed by len narrowing#16470hauntsaninja merged 1 commit intopython:masterfrom
hauntsaninja merged 1 commit intopython:masterfrom
Conversation
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: websockets (https://github.com/aaugustin/websockets)
+ src/websockets/legacy/auth.py:162: error: Argument 1 to "list" has incompatible type "tuple[str, str] | Iterable[tuple[str, str]]"; expected "Iterable[tuple[str, str]]" [arg-type]
vision (https://github.com/pytorch/vision)
+ torchvision/transforms/v2/_geometry.py:254: error: Redundant cast to "tuple[float, float]" [redundant-cast]
+ torchvision/transforms/v2/_geometry.py:257: error: Redundant cast to "tuple[float, float]" [redundant-cast]
|
Member
Author
|
New error in |
sobolevn
reviewed
Nov 12, 2023
| and isinstance(x[0], int) | ||
| and isinstance(x[1], int) | ||
| ): | ||
| reveal_type(x) # N: Revealed type is "Tuple[builtins.int, builtins.int]" |
Member
There was a problem hiding this comment.
Maybe add else: reveal_type(x)? It might give some unexpected result.
Member
Author
There was a problem hiding this comment.
The else branch reveals Union[builtins.int, typing.Sequence[builtins.int], builtins.tuple[Any, ...]] because of the behavior I mentioned in the description. I intentionally didn't add this, since I don't want to create an impression this is intentional.
hauntsaninja
approved these changes
Nov 12, 2023
JukkaL
pushed a commit
that referenced
this pull request
Nov 22, 2023
Fixes #16468 The fix is straightforward. Btw when fixing this I noticed that we disregard type arguments when narrowing, for example: ```python x: Sequence[int] if isinstance(x, tuple): reveal_type(x) # tuple[Any, ...], but should be `tuple[int, ...]` ``` I guess fixing this may be tricky, and it is quite old behavior.
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.
Fixes #16468
The fix is straightforward.
Btw when fixing this I noticed that we disregard type arguments when narrowing, for example:
I guess fixing this may be tricky, and it is quite old behavior.