Skip to content

Commit

Permalink
Hotfix issue 153 (#161)
Browse files Browse the repository at this point in the history
* add failing test

* minimal patch to fix test
  • Loading branch information
neutrinoceros authored Mar 8, 2021
1 parent eb85c48 commit 8d8d37b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ def _to_name_str(node):
# "pkg.mod.error", handling any depth of attribute accesses.
if isinstance(node, ast.Name):
return node.id
assert isinstance(node, ast.Attribute)
return _to_name_str(node.value) + "." + node.attr
try:
return _to_name_str(node.value) + "." + node.attr
except AttributeError:
return _to_name_str(node.value)


def _typesafe_issubclass(cls, class_or_tuple):
Expand Down
14 changes: 14 additions & 0 deletions tests/test_bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,20 @@ def test_does_not_crash_on_site_code(self):
if f.endswith(".py"):
BugBearChecker(filename=str(Path(dirname) / f))

def test_does_not_crash_on_tuple_expansion_in_except_statement(self):
# akin to test_does_not_crash_on_any_valid_code
# but targets a rare case that's not covered by hypothesmith.from_grammar
# see https://github.com/PyCQA/flake8-bugbear/issues/153
syntax_tree = ast.parse(
"grey_list = (ValueError,)\n"
"black_list = (TypeError,)\n"
"try:\n"
" int('1e3')\n"
"except (*grey_list, *black_list):\n"
" print('error caught')"
)
BugBearVisitor(filename="<string>", lines=[]).visit(syntax_tree)


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

0 comments on commit 8d8d37b

Please sign in to comment.