Skip to content

Commit fdfa3a0

Browse files
authored
Do not crash on call in except statement (#187)
1 parent d4e1350 commit fdfa3a0

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

bugbear.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ def _to_name_str(node):
125125
# "pkg.mod.error", handling any depth of attribute accesses.
126126
if isinstance(node, ast.Name):
127127
return node.id
128+
if isinstance(node, ast.Call):
129+
return _to_name_str(node.func)
128130
try:
129131
return _to_name_str(node.value) + "." + node.attr
130132
except AttributeError:

tests/test_bugbear.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,14 @@ def test_does_not_crash_on_tuple_expansion_in_except_statement(self):
339339
)
340340
BugBearVisitor(filename="<string>", lines=[]).visit(syntax_tree)
341341

342+
def test_does_not_crash_on_call_in_except_statement(self):
343+
# akin to test_does_not_crash_on_tuple_expansion_in_except_statement
344+
# see https://github.com/PyCQA/flake8-bugbear/issues/171
345+
syntax_tree = ast.parse(
346+
"foo = lambda: IOError\ntry:\n ...\nexcept (foo(),):\n ...\n"
347+
)
348+
BugBearVisitor(filename="<string>", lines=[]).visit(syntax_tree)
349+
342350

343351
if __name__ == "__main__":
344352
unittest.main()

0 commit comments

Comments
 (0)