-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't emit incorrect-variance for type parameters (PEP 695) #9638
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #9638 +/- ##
==========================================
+ Coverage 95.82% 95.84% +0.01%
==========================================
Files 173 174 +1
Lines 18835 18896 +61
==========================================
+ Hits 18049 18110 +61
Misses 786 786
|
🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉 This comment was generated for commit 40b43ba |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
@@ -659,7 +661,12 @@ def _check_typevar(self, name: str, node: nodes.AssignName) -> None: | |||
if name_arg is None and args and isinstance(args[0], nodes.Const): | |||
name_arg = args[0].value | |||
|
|||
if variance == TypeVarVariance.double_variant: | |||
if variance == TypeVarVariance.inferred: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if variance == TypeVarVariance.inferred: | |
if variance is TypeVarVariance.inferred: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All other comparisons with TypeVarVariance
also use the equals sign.
Let's change it when we implement #5356, maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine!
(cherry picked from commit fbc1ed3)
Type of Changes
Description
Don't emit
typevar-name-incorrect-variance
warnings for PEP 695 style TypeVars.The variance is inferred automatically by the type checker.
Adding
_co
or_contra
suffix can help to reason about TypeVar.