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

Fix scoping for function annotations, decorators and base classes #3713

Merged
merged 2 commits into from Jul 12, 2020

Conversation

anjsimmo
Copy link
Contributor

Steps

  • Add a ChangeLog entry describing what your PR does.
  • Write a good description on what the PR does.

Description

This is a follow up to PR #3497 Fix class scope issues in undefined-variable checker. The earlier PR fixed false positives in which function annotations and decorators were being incorrectly reported as unable to access the class scope due to being incorrectly treated as within the function. This PR fixes false negatives that were caused by still searching the function scope.

Issue #1082, while reported as a false positive for used-before-assignment is really due to a false negative for undefined-variable. Issue #3461 was partially addressed by PR #3497, and this PR fixes the false negative case where we were not reporting type hints that reference the function parameter self (there are still lots of other open type hint issues, but this fixes the specific case reported). Issue #3434 was due to skipping only a single scope level when checking a class's base class list, when there could in fact be an arbitrary number of nested list comprehensions in between. This logic has been moved to a per-scope check similar to the way function annotations and decorators are now checked.

To implement this fix, it was necessary to keep track of the frame/scope node in NamesConsumer, as this may be different to the immediate frame/scope of the variable being checked.

Type of Changes

Type
🐛 Bug fix

Related Issue

Close #1082, #3434, #3461

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.01%) to 90.686% when pulling 84209b5 on anjsimmo:fix-scope into 3d85973 on PyCQA:master.

@coveralls
Copy link

coveralls commented Jun 28, 2020

Coverage Status

Coverage decreased (-0.005%) to 90.693% when pulling 84209b5 on anjsimmo:fix-scope into 3d85973 on PyCQA:master.

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.

Looks really good, thank you.

@Pierre-Sassoulas Pierre-Sassoulas merged commit b0824e9 into pylint-dev:master Jul 12, 2020
@anjsimmo
Copy link
Contributor Author

Thanks @Pierre-Sassoulas, although it seems GitHub only auto-closed #1082. Could you please also close #3434 and close #3461?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

used-before-assignment and undefined-loop-variable false positives with regard to function annotation
3 participants