-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
False positive undefined-variable when variable name in decoration matches function argument #3791
Comments
We're hitting this as well. The other requirement of this is that the variable needs to be used twice in a list comprehension in the decorator. (This is really remarkably specific!) So for instance, these all give the false-positive
But this does not:
Neither do other ways of declaring and introducing new variables, for instance lambdas. These are both fine:
This is also broken in pylint 2.7. |
I believe this is relevant place to patch # if the name node is used as a function default argument's value or as
# a decorator, then start from the parent frame of the function instead
# of the function frame - and thus open an inner class scope
if (
current_consumer.scope_type == "function"
and self._defined_in_function_definition(node, current_consumer.node)
):
# ignore function scope if is an annotation/default/decorator, as not in the body
continue Relevant issue: #1731 |
The `undefined-variable` pylint plugin can now be re-added in, as it was removed until [an underlying issue](pylint-dev/pylint#3791) had been fixed.
Update pylint to 2.9.6 to get around a false positive for undefined-variable in a decorator. pylint-dev/pylint#3791
The `undefined-variable` pylint plugin can now be re-added in, as it was removed until [an underlying issue](pylint-dev/pylint#3791) had been fixed.
Steps to reproduce
Run pylint on the following code:
Current behavior
pylint reports:
Line 4 being the
@decorate
precedingf()
.Note that no error is reported for
g()
: the problem only occurs if the variable name inside the comprehension matches one of the decorated function's arguments. Which is strange, since they should be in separate scopes.Expected behavior
No error is reported.
pylint --version output
This problem did not occur until I upgraded from pylint 2.5.3 to 2.6.0.
The text was updated successfully, but these errors were encountered: