Skip to content
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

Merged
merged 1 commit into from
May 17, 2024

Conversation

cdce8p
Copy link
Member

@cdce8p cdce8p commented May 16, 2024

Type of Changes

Type
🐛 Bug fix

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.

Copy link

codecov bot commented May 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.84%. Comparing base (7521eb1) to head (40b43ba).
Report is 177 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            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              
Files Coverage Δ
pylint/checkers/base/name_checker/checker.py 98.64% <100.00%> (+0.01%) ⬆️

... and 7 files with indirect coverage changes

Copy link
Contributor

🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉

This comment was generated for commit 40b43ba

Copy link
Collaborator

@DanielNoord DanielNoord left a 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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if variance == TypeVarVariance.inferred:
if variance is TypeVarVariance.inferred:

Copy link
Member Author

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?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine!

pylint/checkers/base/name_checker/checker.py Show resolved Hide resolved
@cdce8p cdce8p merged commit fbc1ed3 into pylint-dev:main May 17, 2024
48 checks passed
@cdce8p cdce8p deleted the pep695-variance branch May 17, 2024 07:16
github-actions bot pushed a commit that referenced this pull request May 17, 2024
Pierre-Sassoulas added a commit that referenced this pull request May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants