diff --git a/bugbear.py b/bugbear.py index b47f0d7..1de708f 100644 --- a/bugbear.py +++ b/bugbear.py @@ -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: diff --git a/tests/test_bugbear.py b/tests/test_bugbear.py index 6a0fb55..445918d 100644 --- a/tests/test_bugbear.py +++ b/tests/test_bugbear.py @@ -339,6 +339,14 @@ def test_does_not_crash_on_tuple_expansion_in_except_statement(self): ) BugBearVisitor(filename="", 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="", lines=[]).visit(syntax_tree) + if __name__ == "__main__": unittest.main()