@@ -387,6 +387,7 @@ def visit_Raise(self, node):
387
387
388
388
def visit_With (self , node ):
389
389
self .check_for_b017 (node )
390
+ self .check_for_b022 (node )
390
391
self .generic_visit (node )
391
392
392
393
def compose_call_path (self , node ):
@@ -739,6 +740,20 @@ def check_for_b021(self, node):
739
740
B021 (node .body [0 ].value .lineno , node .body [0 ].value .col_offset )
740
741
)
741
742
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
+
742
757
743
758
@attr .s
744
759
class NameFinder (ast .NodeVisitor ):
@@ -965,6 +980,13 @@ def visit(self, node):
965
980
"This will be interpreted by python as a joined string rather than a docstring."
966
981
)
967
982
)
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
+ )
968
990
969
991
# Warnings disabled by default.
970
992
B901 = Error (
0 commit comments