summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdi Roiban <adi.roiban@chevah.com>2015-02-14 15:05:11 +0000
committerAdi Roiban <adi.roiban@chevah.com>2015-02-14 15:05:11 +0000
commit2171de4f23e837ade4e76061719b1fd1c804f8cf (patch)
tree0a426ce926aee5f76cf6e94411bba096214f021f
parent4bfe6751b4b9b40013cab29769b9c4712558669e (diff)
downloadpyflakes-2171de4f23e837ade4e76061719b1fd1c804f8cf.tar.gz
Update after bitglue's review.
-rw-r--r--pyflakes/checker.py24
-rw-r--r--pyflakes/test/test_undefined_names.py21
2 files changed, 13 insertions, 32 deletions
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
index 9cbe790..448e6c1 100644
--- a/pyflakes/checker.py
+++ b/pyflakes/checker.py
@@ -534,32 +534,15 @@ class Checker(object):
def on_conditional_branch():
"""
- Return `True` if node is part of a conditional branch.
+ Return `True` if node is part of a conditional body.
"""
current = getattr(node, 'parent', None)
while current:
- if isinstance(current, ast.If):
+ if isinstance(current, (ast.If, ast.While, ast.IfExp)):
return True
current = getattr(current, 'parent', None)
return False
- def is_part_of_while_conditional():
- """
- Return `True` if node is part of left or right side of a while
- test.
- """
- current = getattr(node, 'parent', None)
- while current:
- if isinstance(current, ast.While):
- for descendant in ast.walk(current.test):
- if not isinstance(descendant, ast.Name):
- continue
- if not node.id == descendant.id:
- continue
- return True
- current = getattr(current, 'parent', None)
- return False
-
name = getNodeName(node)
if not name:
return
@@ -569,9 +552,6 @@ class Checker(object):
# be executed.
return
- if is_part_of_while_conditional():
- return
-
if isinstance(self.scope, FunctionScope) and name in self.scope.globals:
self.scope.globals.remove(name)
else:
diff --git a/pyflakes/test/test_undefined_names.py b/pyflakes/test/test_undefined_names.py
index 4dc0a77..165999d 100644
--- a/pyflakes/test/test_undefined_names.py
+++ b/pyflakes/test/test_undefined_names.py
@@ -150,25 +150,26 @@ class Test(TestCase):
def test_delWhile(self):
"""
- Ignore bindings deletion if node is part of while test's left side.
+ Ignore bindings deletion if called inside the body of a while
+ statement.
"""
self.flakes('''
- def _worker():
- o = True
- while o is not True:
- del o
- o = False
+ def test():
+ foo = 'bar'
+ while False:
+ del foo
+ print foo
''')
- def test_delWhileRightSide(self):
+ def test_delWhileTestUsage(self):
"""
- Ignore bindings deletion if node is part of while test's right side.
+ Ignore bindings deletion if called inside the body of a while
+ statement and name is used inside while's test part.
"""
self.flakes('''
def _worker():
- a = False
o = True
- while a == o:
+ while o is not True:
del o
o = False
''')