Skip to content

Fix #5568: Allow nested classes as return annotations #5688

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

Merged

Conversation

jacobtylerwalls
Copy link
Member

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

The undefined-variable checker had a special case for return annotations matching the name of the containing class, but this missed other nested classes like a namedtuple used as a class attribute.

Closes #5568

maybe_before_assign = False
annotation_return = True
if (
frame.returns.name in defframe.locals
Copy link
Member Author

Choose a reason for hiding this comment

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

The only substantive change in the PR is to change defframe.name to frame.returns.name. The rest is just refactoring for readability and avoiding re-checking the same boolean maybe_before_assign.

@coveralls
Copy link

coveralls commented Jan 16, 2022

Pull Request Test Coverage Report for Build 1704780241

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 93.848%

Totals Coverage Status
Change from base Build 1702082973: 0.01%
Covered Lines: 14690
Relevant Lines: 15653

πŸ’› - Coveralls

@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.13.0 milestone Jan 16, 2022
@Pierre-Sassoulas Pierre-Sassoulas added the False Positive 🦟 A message is emitted but nothing is wrong with the code label Jan 16, 2022
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

Thank you for the little refactor on top of the fix πŸ˜„ !

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 once again @jacobtylerwalls!

@Pierre-Sassoulas Pierre-Sassoulas merged commit a6a10e5 into pylint-dev:main Jan 16, 2022
@jacobtylerwalls jacobtylerwalls deleted the return-annotation-namedtuple branch January 16, 2022 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect "undefined variable" error for named tuple class variables as return type annotations
4 participants