diff options
author | Torsten Marek <tmarek@google.com> | 2012-03-15 13:48:25 +0100 |
---|---|---|
committer | Torsten Marek <tmarek@google.com> | 2012-03-15 13:48:25 +0100 |
commit | 442d90383827cc06061124c2942c540d3588eae1 (patch) | |
tree | df8a189356d2bad4cddaae194cb31e7e62320651 | |
parent | f6ad8e26b9586d280d42581b721ce2d3e9124b1e (diff) | |
download | pylint-git-442d90383827cc06061124c2942c540d3588eae1.tar.gz |
Fix the variables check to not emit false positives for E0602 on {list,generator} comprehension loop variables inside decorators.
Closes #77982
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | checkers/utils.py | 6 | ||||
-rw-r--r-- | test/input/func_undefined_var.py | 16 |
3 files changed, 24 insertions, 1 deletions
@@ -3,6 +3,9 @@ ChangeLog for PyLint -- + * #77982 Do not emit E0602 for loop variables of comprehensions + used as argument values inside a decorator (patch by tmarek@google.com) + * #87192 fix crash when decorators are accessed through more than one dot (for instance @a.b is fine, @a.b.c crash) * #89092: don't emit E0202 (attribute hiding a method) on @property methods diff --git a/checkers/utils.py b/checkers/utils.py index 95574d4ef..efaa7ada8 100644 --- a/checkers/utils.py +++ b/checkers/utils.py @@ -20,6 +20,7 @@ import string from logilab import astng +from logilab.astng import scoped_nodes from logilab.common.compat import builtins BUILTINS_NAME = builtins.__name__ @@ -169,7 +170,10 @@ def is_func_decorator(node): while parent is not None: if isinstance(parent, astng.Decorators): return True - if parent.is_statement or isinstance(parent, astng.Lambda): + if (parent.is_statement or + isinstance(parent, astng.Lambda) or + isinstance(parent, (scoped_nodes.ComprehensionScope, + scoped_nodes.ListComp))): break parent = parent.parent return False diff --git a/test/input/func_undefined_var.py b/test/input/func_undefined_var.py index 5d46f0104..27a9ed616 100644 --- a/test/input/func_undefined_var.py +++ b/test/input/func_undefined_var.py @@ -67,3 +67,19 @@ def if_branch_test(something): else: print xxx xxx = 3 + + +def decorator(arg): + """Decorator with one argument.""" + return lambda: list(arg) + + +@decorator(arg=[i * 2 for i in range(15)]) +def func1(): + """A function with a decorator that contains a listcomp.""" + pass + +@decorator(arg=(i * 2 for i in range(15))) +def func2(): + """A function with a decorator that contains a genexpr.""" + pass |