Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix issue 153 #161

Merged
merged 2 commits into from Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions bugbear.py
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
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()