Fixed a bug in the type narrowing logic for the S in D type guard p…#10378
Merged
Fixed a bug in the type narrowing logic for the S in D type guard p…#10378
S in D type guard p…#10378Conversation
…attern (where S is a string literal and D is a TypedDict). If the TypedDict is not closed, the absence of the key within the TypedDict definition cannot eliminate the type during narrowing. This addresses #10376.
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: sympy (https://github.com/sympy/sympy)
- /tmp/mypy_primer/projects/sympy/sympy/utilities/matchpy_connector.py:288:16 - error: Type "Basic" is not assignable to declared type "Expr"
- "Basic" is not assignable to "Expr" (reportAssignmentType)
- 32773 errors, 72 warnings, 0 informations
+ 32772 errors, 72 warnings, 0 informations
strawberry (https://github.com/strawberry-graphql/strawberry)
- /tmp/mypy_primer/projects/strawberry/strawberry/channels/testing.py:153:54 - error: Argument of type "list[GraphQLFormattedError] | object | Unknown" cannot be assigned to parameter "errors" of type "list[GraphQLFormattedError]" in function "process_errors"
+ /tmp/mypy_primer/projects/strawberry/strawberry/channels/testing.py:153:54 - error: Argument of type "Any | list[GraphQLFormattedError] | object | Unknown" cannot be assigned to parameter "errors" of type "list[GraphQLFormattedError]" in function "process_errors"
- Type "list[GraphQLFormattedError] | object | Unknown" is not assignable to type "list[GraphQLFormattedError]"
+ Type "Any | list[GraphQLFormattedError] | object | Unknown" is not assignable to type "list[GraphQLFormattedError]"
|
This was referenced Jun 23, 2025
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.
…attern (where S is a string literal and D is a TypedDict). If the TypedDict is not closed, the absence of the key within the TypedDict definition cannot eliminate the type during narrowing. This addresses #10376.