diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2014-03-30 04:36:09 +0200 |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2014-03-30 04:36:09 +0200 |
commit | a55a126350880ef378cb7e8d6576e400d7f6205d (patch) | |
tree | c4d135e04bba40297e21fb8c5e236988a84b6432 | |
parent | 4417b7730c3e42087d3adb56d13bd4756d05b0bc (diff) | |
download | pyflakes-a55a126350880ef378cb7e8d6576e400d7f6205d.tar.gz |
Refactoring
-rw-r--r-- | pyflakes/checker.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/pyflakes/checker.py b/pyflakes/checker.py index 993a4fc..f58bc70 100644 --- a/pyflakes/checker.py +++ b/pyflakes/checker.py @@ -355,7 +355,7 @@ class Checker(object): messg = messages.UnusedImport self.report(messg, value.source, value.name) for node in value.redefined: - if self.hasParent(node, ast.For): + if isinstance(self.getParent(node), ast.For): messg = messages.ImportShadowedByLoopVar elif used: continue @@ -370,14 +370,12 @@ class Checker(object): self.messages.append(messageClass(self.filename, *args, **kwargs)) def getParent(self, node): + # Lookup the first parent which is not Tuple, List or Starred while True: node = node.parent if not hasattr(node, 'elts') and not hasattr(node, 'ctx'): return node - def hasParent(self, node, kind): - return isinstance(self.getParent(node), kind) - def getCommonAncestor(self, lnode, rnode, stop=None): if not stop: stop = self.root @@ -436,13 +434,15 @@ class Checker(object): if existing and not self.differentForks(node, existing.source): - if isinstance(existing, Importation) and self.hasParent(value.source, ast.For): + parent_stmt = self.getParent(value.source) + if isinstance(existing, Importation) and isinstance(parent_stmt, ast.For): self.report(messages.ImportShadowedByLoopVar, node, value.name, existing.source) elif scope is self.scope: - if (self.hasParent(value.source, ast.comprehension) and - not self.hasParent(existing.source, (ast.For, ast.comprehension))): + if (isinstance(parent_stmt, ast.comprehension) and + not isinstance(self.getParent(existing.source), + (ast.For, ast.comprehension))): self.report(messages.RedefinedInListComp, node, value.name, existing.source) elif not existing.used and value.redefines(existing): |