Skip to content

Commit 189b993

Browse files
jaap3Jaap Roes
authored andcommitted
Do not crash on call in except statement
1 parent 8210776 commit 189b993

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,18 @@ def test_does_not_crash_on_tuple_expansion_in_except_statement(self):
336336
)
337337
BugBearVisitor(filename="<string>", lines=[]).visit(syntax_tree)
338338

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

340352
if __name__ == "__main__":
341353
unittest.main()

0 commit comments

Comments
 (0)