@@ -276,15 +276,12 @@ def visit(self, node):
276
276
277
277
def visit_ExceptHandler (self , node ):
278
278
if node .type is None :
279
- self .errors .append (
280
- B001 (node .lineno , node .col_offset , vars = ("bare `except:`" ,))
281
- )
279
+ self .errors .append (B001 (node .lineno , node .col_offset ))
282
280
elif isinstance (node .type , ast .Tuple ):
283
281
names = [_to_name_str (e ) for e in node .type .elts ]
284
282
as_ = " as " + node .name if node .name is not None else ""
285
283
if len (names ) == 0 :
286
- vs = (f"`except (){ as_ } :`" ,)
287
- self .errors .append (B001 (node .lineno , node .col_offset , vars = vs ))
284
+ self .errors .append (B029 (node .lineno , node .col_offset ))
288
285
elif len (names ) == 1 :
289
286
self .errors .append (B013 (node .lineno , node .col_offset , vars = names ))
290
287
else :
@@ -1285,7 +1282,7 @@ def visit_Lambda(self, node):
1285
1282
1286
1283
B001 = Error (
1287
1284
message = (
1288
- "B001 Do not use {} , it also catches unexpected "
1285
+ "B001 Do not use bare `except:` , it also catches unexpected "
1289
1286
"events like memory errors, interrupts, system exit, and so on. "
1290
1287
"Prefer `except Exception:`. If you're sure what you're doing, "
1291
1288
"be explicit and write `except BaseException:`."
@@ -1530,6 +1527,12 @@ def visit_Lambda(self, node):
1530
1527
" greater to provide more information to the user."
1531
1528
)
1532
1529
)
1530
+ B029 = Error (
1531
+ message = (
1532
+ "B029 Using `except: ()` with an empty tuple does not handle/catch "
1533
+ "anything. Add exceptions to handle."
1534
+ )
1535
+ )
1533
1536
1534
1537
# Warnings disabled by default.
1535
1538
B901 = Error (
0 commit comments