@@ -387,6 +387,7 @@ def visit_Raise(self, node):
387387
388388 def visit_With (self , node ):
389389 self .check_for_b017 (node )
390+ self .check_for_b022 (node )
390391 self .generic_visit (node )
391392
392393 def compose_call_path (self , node ):
@@ -739,6 +740,20 @@ def check_for_b021(self, node):
739740 B021 (node .body [0 ].value .lineno , node .body [0 ].value .col_offset )
740741 )
741742
743+ def check_for_b022 (self , node ):
744+ item = node .items [0 ]
745+ item_context = item .context_expr
746+ if (
747+ hasattr (item_context , "func" )
748+ and hasattr (item_context .func , "value" )
749+ and hasattr (item_context .func .value , "id" )
750+ and item_context .func .value .id == "contextlib"
751+ and hasattr (item_context .func , "attr" )
752+ and item_context .func .attr == "suppress"
753+ and len (item_context .args ) == 0
754+ ):
755+ self .errors .append (B022 (node .lineno , node .col_offset ))
756+
742757
743758@attr .s
744759class NameFinder (ast .NodeVisitor ):
@@ -965,6 +980,13 @@ def visit(self, node):
965980 "This will be interpreted by python as a joined string rather than a docstring."
966981 )
967982)
983+ B022 = Error (
984+ message = (
985+ "B022 No arguments passed to `contextlib.suppress`."
986+ "No exceptions will be suppressed and therefore this"
987+ "context manager is redundant."
988+ )
989+ )
968990
969991# Warnings disabled by default.
970992B901 = Error (
0 commit comments