diff --git a/pyflakes/checker.py b/pyflakes/checker.py index b87bc886..15b4c2bf 100644 --- a/pyflakes/checker.py +++ b/pyflakes/checker.py @@ -1068,7 +1068,7 @@ def getNodeHandler(self, node_class): ) return handler - def handleNodeLoad(self, node): + def handleNodeLoad(self, node, parent): name = getNodeName(node) if not name: return @@ -1093,7 +1093,6 @@ def handleNodeLoad(self, node): continue if name == 'print' and isinstance(binding, Builtin): - parent = self.getParent(node) if (isinstance(parent, ast.BinOp) and isinstance(parent.op, ast.RShift)): self.report(messages.InvalidPrintSyntax, node) @@ -1880,7 +1879,7 @@ def NAME(self, node): """ # Locate the name in locals / function / globals scopes. if isinstance(node.ctx, ast.Load): - self.handleNodeLoad(node) + self.handleNodeLoad(node, self.getParent(node)) if (node.id == 'locals' and isinstance(self.scope, FunctionScope) and isinstance(node._pyflakes_parent, ast.Call)): # we are doing locals() call in current scope @@ -2049,7 +2048,7 @@ def CLASSDEF(self, node): self.addBinding(node, ClassDefinition(node.name, node)) def AUGASSIGN(self, node): - self.handleNodeLoad(node.target) + self.handleNodeLoad(node.target, node) self.handleNode(node.value, node) self.handleNode(node.target, node) diff --git a/pyflakes/test/test_other.py b/pyflakes/test/test_other.py index b138cf6e..ce742a58 100644 --- a/pyflakes/test/test_other.py +++ b/pyflakes/test/test_other.py @@ -2052,6 +2052,10 @@ def test_invalid_print_when_imported_from_future(self): self.assertEqual(exc.lineno, 4) self.assertEqual(exc.col, 0) + def test_print_augmented_assign(self): + # nonsense, but shouldn't crash pyflakes + self.flakes('print += 1') + def test_print_function_assignment(self): """ A valid assignment, tested for catching false positives.