diff options
author | Anthony Sottile <asottile@umich.edu> | 2018-05-22 00:35:46 -0700 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2018-05-22 09:37:37 +0200 |
commit | 6b4c4d24f15ebaf0d08e42984329ee56a0a3d207 (patch) | |
tree | 64d762df5c94f4b7a701a172b33a2a200c8901eb | |
parent | 3896ed627009f9547d1ca7fbf7d2d1156e0e89ad (diff) | |
download | pylint-git-6b4c4d24f15ebaf0d08e42984329ee56a0a3d207.tar.gz |
Use last previous assignment for comprehension-escape (#2131)
-rw-r--r-- | pylint/checkers/python3.py | 7 | ||||
-rw-r--r-- | pylint/test/unittest_checker_python3.py | 9 |
2 files changed, 13 insertions, 3 deletions
diff --git a/pylint/checkers/python3.py b/pylint/checkers/python3.py index 1e988f63b..f2efa18d1 100644 --- a/pylint/checkers/python3.py +++ b/pylint/checkers/python3.py @@ -638,9 +638,10 @@ class Python3Checker(checkers.BaseChecker): # On Python 3 we don't find the leaked objects as # they are already deleted, so instead look for them manually. scope = node.scope() - assign_names = (node_ for node_ in scope.nodes_of_class(astroid.AssignName) - if node_.name == node.name and node_.lineno < node.lineno) - assigned = next(assign_names, None) + assigned = None + for node_ in scope.nodes_of_class(astroid.AssignName): + if node_.name == node.name and node_.lineno < node.lineno: + assigned = node_ if not assigned: return diff --git a/pylint/test/unittest_checker_python3.py b/pylint/test/unittest_checker_python3.py index b6f98ad70..8e1bce493 100644 --- a/pylint/test/unittest_checker_python3.py +++ b/pylint/test/unittest_checker_python3.py @@ -735,6 +735,15 @@ class TestPython3Checker(testutils.CheckerTestCase): with self.assertNoMessages(): self.checker.visit_name(node) + def test_comprehension_escape_newly_introduced(self): + node = astroid.extract_node(''' + [i for i in range(3)] + for i in range(3): + i + ''') + with self.assertNoMessages(): + self.walk(node) + def test_exception_escape(self): bad, good = astroid.extract_node(''' try: 1/0 |