@@ -276,15 +276,12 @@ def visit(self, node):
276276
277277 def visit_ExceptHandler (self , node ):
278278 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 ))
282280 elif isinstance (node .type , ast .Tuple ):
283281 names = [_to_name_str (e ) for e in node .type .elts ]
284282 as_ = " as " + node .name if node .name is not None else ""
285283 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 ))
288285 elif len (names ) == 1 :
289286 self .errors .append (B013 (node .lineno , node .col_offset , vars = names ))
290287 else :
@@ -1285,7 +1282,7 @@ def visit_Lambda(self, node):
12851282
12861283B001 = Error (
12871284 message = (
1288- "B001 Do not use {} , it also catches unexpected "
1285+ "B001 Do not use bare `except:` , it also catches unexpected "
12891286 "events like memory errors, interrupts, system exit, and so on. "
12901287 "Prefer `except Exception:`. If you're sure what you're doing, "
12911288 "be explicit and write `except BaseException:`."
@@ -1530,6 +1527,12 @@ def visit_Lambda(self, node):
15301527 " greater to provide more information to the user."
15311528 )
15321529)
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+ )
15331536
15341537# Warnings disabled by default.
15351538B901 = Error (
0 commit comments