Skip to content

Commit

Permalink
Do not crash on call in except statement (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaap3 committed Sep 28, 2021
1 parent d4e1350 commit fdfa3a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bugbear.py
Expand Up @@ -125,6 +125,8 @@ def _to_name_str(node):
# "pkg.mod.error", handling any depth of attribute accesses.
if isinstance(node, ast.Name):
return node.id
if isinstance(node, ast.Call):
return _to_name_str(node.func)
try:
return _to_name_str(node.value) + "." + node.attr
except AttributeError:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_bugbear.py
Expand Up @@ -339,6 +339,14 @@ def test_does_not_crash_on_tuple_expansion_in_except_statement(self):
)
BugBearVisitor(filename="<string>", lines=[]).visit(syntax_tree)

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


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

0 comments on commit fdfa3a0

Please sign in to comment.