@@ -32,7 +32,17 @@ class BugBearChecker:
32
32
def run (self ):
33
33
if not self .tree or not self .lines :
34
34
self .load_file ()
35
- visitor = self .visitor (filename = self .filename , lines = self .lines )
35
+
36
+ if self .options and hasattr (self .options , "extend_immutable_calls" ):
37
+ b008_extend_immutable_calls = set (self .options .extend_immutable_calls )
38
+ else :
39
+ b008_extend_immutable_calls = set ()
40
+
41
+ visitor = self .visitor (
42
+ filename = self .filename ,
43
+ lines = self .lines ,
44
+ b008_extend_immutable_calls = b008_extend_immutable_calls ,
45
+ )
36
46
visitor .visit (self .tree )
37
47
for e in itertools .chain (visitor .errors , self .gen_line_based_checks ()):
38
48
if self .should_warn (e .message [:4 ]):
@@ -73,6 +83,13 @@ def load_file(self):
73
83
def add_options (optmanager ):
74
84
"""Informs flake8 to ignore B9xx by default."""
75
85
optmanager .extend_default_ignore (disabled_by_default )
86
+ optmanager .add_option (
87
+ "--extend-immutable-calls" ,
88
+ comma_separated_list = True ,
89
+ parse_from_config = True ,
90
+ default = [],
91
+ help = "Skip B008 test for additional immutable calls." ,
92
+ )
76
93
77
94
@lru_cache ()
78
95
def should_warn (self , code ):
@@ -146,6 +163,7 @@ def _typesafe_issubclass(cls, class_or_tuple):
146
163
class BugBearVisitor (ast .NodeVisitor ):
147
164
filename = attr .ib ()
148
165
lines = attr .ib ()
166
+ b008_extend_immutable_calls = attr .ib (default = attr .Factory (set ))
149
167
node_stack = attr .ib (default = attr .Factory (list ))
150
168
node_window = attr .ib (default = attr .Factory (list ))
151
169
errors = attr .ib (default = attr .Factory (list ))
@@ -338,7 +356,10 @@ def check_for_b006(self, node):
338
356
call_path = "." .join (self .compose_call_path (default .func ))
339
357
if call_path in B006 .mutable_calls :
340
358
self .errors .append (B006 (default .lineno , default .col_offset ))
341
- elif call_path not in B008 .immutable_calls :
359
+ elif (
360
+ call_path
361
+ not in B008 .immutable_calls | self .b008_extend_immutable_calls
362
+ ):
342
363
# Check if function call is actually a float infinity/NaN literal
343
364
if call_path == "float" and len (default .args ) == 1 :
344
365
float_arg = default .args [0 ]
0 commit comments