summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2022-11-24 11:51:46 -0500
committerGitHub <noreply@github.com>2022-11-24 11:51:46 -0500
commite0d7a6be89591f913beb740af348df8b7723e7a4 (patch)
treed24f6e2127bf9155a689a82802c51670cb666749
parent2c64ae48e2b1984a16cf25d215c9f9d21146426d (diff)
downloadpyflakes-e0d7a6be89591f913beb740af348df8b7723e7a4.tar.gz
fix crash on augmented-assign to print builtin (#745)
-rw-r--r--pyflakes/checker.py7
-rw-r--r--pyflakes/test/test_other.py4
2 files changed, 7 insertions, 4 deletions
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
index b87bc88..15b4c2b 100644
--- a/pyflakes/checker.py
+++ b/pyflakes/checker.py
@@ -1068,7 +1068,7 @@ class Checker:
)
return handler
- def handleNodeLoad(self, node):
+ def handleNodeLoad(self, node, parent):
name = getNodeName(node)
if not name:
return
@@ -1093,7 +1093,6 @@ class Checker:
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 @@ class Checker:
"""
# 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 @@ class Checker:
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 b138cf6..ce742a5 100644
--- a/pyflakes/test/test_other.py
+++ b/pyflakes/test/test_other.py
@@ -2052,6 +2052,10 @@ class TestIncompatiblePrintOperator(TestCase):
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.