You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix constrained TypeVar narrowing for issubclass - #11951
Root cause
Control-flow narrowing for constrained TypeVars recognized only isinstance conditions. An issubclass condition receives type[T], so the return-type checker could not associate the narrowed class with the constrained instance TypeVar T.
Fix strategy
Recognize issubclass in constrained-TypeVar flow analysis and remove one instantiable layer from type[T] before matching it to T. Add positive and negative branch coverage to the existing constrained TypeVar sample.
Diagnostic ranges use zero-based line and character positions.
This branch has not been deployed
No deployments
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
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.
fix: #11946
Root cause
Control-flow narrowing for constrained TypeVars recognized only
isinstanceconditions. Anissubclasscondition receivestype[T], so the return-type checker could not associate the narrowed class with the constrained instance TypeVarT.Fix strategy
Recognize
issubclassin constrained-TypeVar flow analysis and remove one instantiable layer fromtype[T]before matching it toT. Add positive and negative branch coverage to the existing constrained TypeVar sample.The relevant test suite passes with 164 tests.