Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix crash on augmented-assign to print builtin #745

Merged
merged 1 commit into from Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions pyflakes/checker.py
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions pyflakes/test/test_other.py
Expand Up @@ -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.
Expand Down