Narrow membership in statically known containers#21461
Merged
Merged
Conversation
This comment has been minimized.
This comment has been minimized.
ilevkivskyi
approved these changes
May 12, 2026
Member
ilevkivskyi
left a comment
There was a problem hiding this comment.
Nice, just one small question.
| container_item_types = p_iterable_type.items | ||
| else: | ||
| container_expr = collapse_walrus(operands[right_index]) | ||
| if isinstance(container_expr, (TupleExpr, ListExpr, SetExpr)): |
Member
There was a problem hiding this comment.
Shouldn't the branch above always cover the TupleExpr case? Or do we sometimes infer non-tuple type for a tuple literal? If you know such situation it may be worth adding a specific test case.
Collaborator
Author
There was a problem hiding this comment.
Yeah, I think it should be always covered. Code ended up this way due to some refactoring I did, updated. Also added some more tests
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: altair (https://github.com/vega/altair)
+ altair/utils/mimebundle.py:138: error: Redundant cast to "Literal['png', 'svg', 'pdf', 'vega']" [redundant-cast]
rotki (https://github.com/rotki/rotki)
+ rotkehlchen/history/events/structures/swap.py:176: error: Unused "type: ignore" comment [unused-ignore]
manticore (https://github.com/trailofbits/manticore)
+ manticore/wasm/executor.py:402: error: Unused "type: ignore" comment [unused-ignore]
+ manticore/wasm/executor.py:1226: error: Unused "type: ignore" comment [unused-ignore]
+ manticore/wasm/structure.py:1105: error: Unused "type: ignore" comment [unused-ignore]
sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/ext/autodoc/_dynamic/_loader.py:237: error: Unused "type: ignore" comment [unused-ignore]
+ sphinx/ext/autodoc/_dynamic/_loader.py:260: error: Unused "type: ignore" comment [unused-ignore]
paasta (https://github.com/yelp/paasta)
+ paasta_tools/kubernetes_tools.py:693: error: Redundant cast to "NodeSelectorInNotIn" [redundant-cast]
+ paasta_tools/kubernetes_tools.py:696: error: Redundant cast to "NodeSelectorExistsDoesNotExist" [redundant-cast]
+ paasta_tools/kubernetes_tools.py:699: error: Redundant cast to "NodeSelectorGtLt" [redundant-cast]
|
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.
The negative narrowing here could be more aggressive, but we will need better literal handling to unblock it
Builds on #21456
Fixes #13684 in combination with previous PRs. There is one remaining diagnostic, but that one is desirable