File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -124,8 +124,10 @@ def _to_name_str(node):
124
124
# "pkg.mod.error", handling any depth of attribute accesses.
125
125
if isinstance (node , ast .Name ):
126
126
return node .id
127
- assert isinstance (node , ast .Attribute )
128
- return _to_name_str (node .value ) + "." + node .attr
127
+ try :
128
+ return _to_name_str (node .value ) + "." + node .attr
129
+ except AttributeError :
130
+ return _to_name_str (node .value )
129
131
130
132
131
133
def _typesafe_issubclass (cls , class_or_tuple ):
Original file line number Diff line number Diff line change @@ -340,6 +340,20 @@ def test_does_not_crash_on_site_code(self):
340
340
if f .endswith (".py" ):
341
341
BugBearChecker (filename = str (Path (dirname ) / f ))
342
342
343
+ def test_does_not_crash_on_tuple_expansion_in_except_statement (self ):
344
+ # akin to test_does_not_crash_on_any_valid_code
345
+ # but targets a rare case that's not covered by hypothesmith.from_grammar
346
+ # see https://github.com/PyCQA/flake8-bugbear/issues/153
347
+ syntax_tree = ast .parse (
348
+ "grey_list = (ValueError,)\n "
349
+ "black_list = (TypeError,)\n "
350
+ "try:\n "
351
+ " int('1e3')\n "
352
+ "except (*grey_list, *black_list):\n "
353
+ " print('error caught')"
354
+ )
355
+ BugBearVisitor (filename = "<string>" , lines = []).visit (syntax_tree )
356
+
343
357
344
358
if __name__ == "__main__" :
345
359
unittest .main ()
You can’t perform that action at this time.
0 commit comments