File tree Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change 325
325
Change Log
326
326
----------
327
327
328
+ Unreleased
329
+ ~~~~~~~~~~
330
+
331
+ * B030: Allow calls and starred expressions in except handlers.
332
+
328
333
23.2.13
329
334
~~~~~~~~~
330
335
Original file line number Diff line number Diff line change @@ -333,17 +333,25 @@ def visit_ExceptHandler(self, node):
333
333
handlers = _flatten_excepthandler (node .type )
334
334
good_handlers = []
335
335
bad_handlers = []
336
+ ignored_handlers = []
336
337
for handler in handlers :
337
338
if isinstance (handler , (ast .Name , ast .Attribute )):
338
339
good_handlers .append (handler )
340
+ elif isinstance (handler , (ast .Call , ast .Starred )):
341
+ ignored_handlers .append (handler )
339
342
else :
340
343
bad_handlers .append (handler )
341
344
if bad_handlers :
342
345
self .errors .append (B030 (node .lineno , node .col_offset ))
343
346
names = [_to_name_str (e ) for e in good_handlers ]
344
- if len (names ) == 0 and not bad_handlers :
347
+ if len (names ) == 0 and not bad_handlers and not ignored_handlers :
345
348
self .errors .append (B029 (node .lineno , node .col_offset ))
346
- elif len (names ) == 1 and not bad_handlers and isinstance (node .type , ast .Tuple ):
349
+ elif (
350
+ len (names ) == 1
351
+ and not bad_handlers
352
+ and not ignored_handlers
353
+ and isinstance (node .type , ast .Tuple )
354
+ ):
347
355
self .errors .append (B013 (node .lineno , node .col_offset , vars = names ))
348
356
else :
349
357
maybe_error = _check_redundant_excepthandlers (names , node )
Original file line number Diff line number Diff line change 12
12
pass
13
13
except (1 , ValueError ): # error
14
14
pass
15
+
16
+ try :
17
+ pass
18
+ except (ValueError , * (RuntimeError , TypeError )): # ok
19
+ pass
20
+
21
+
22
+ def what_to_catch ():
23
+ return (ValueError , TypeError )
24
+
25
+
26
+ try :
27
+ pass
28
+ except what_to_catch (): # ok
29
+ pass
You can’t perform that action at this time.
0 commit comments