@@ -180,6 +180,7 @@ class ConfigurationParser:
180
180
'match' ,
181
181
'match-dir' ,
182
182
'ignore-decorators' ,
183
+ 'ignore-functions' ,
183
184
)
184
185
BASE_ERROR_SELECTION_OPTIONS = ('ignore' , 'select' , 'convention' )
185
186
@@ -189,6 +190,7 @@ class ConfigurationParser:
189
190
DEFAULT_PROPERTY_DECORATORS = (
190
191
"property,cached_property,functools.cached_property"
191
192
)
193
+ DEFAULT_IGNORE_FUNCTIONS_RE = ''
192
194
DEFAULT_CONVENTION = conventions .pep257
193
195
194
196
PROJECT_CONFIG_FILES = (
@@ -263,6 +265,10 @@ def _get_matches(conf):
263
265
match_dir_func = re (conf .match_dir + '$' ).match
264
266
return match_func , match_dir_func
265
267
268
+ def _get_ignore_functions (conf ):
269
+ """Return the `ignore_functions` as None or regex."""
270
+ return re (conf .ignore_functions ) if conf .ignore_functions else None
271
+
266
272
def _get_ignore_decorators (conf ):
267
273
"""Return the `ignore_decorators` as None or regex."""
268
274
return (
@@ -284,6 +290,7 @@ def _get_property_decorators(conf):
284
290
match , match_dir = _get_matches (config )
285
291
ignore_decorators = _get_ignore_decorators (config )
286
292
property_decorators = _get_property_decorators (config )
293
+ ignore_functions = _get_ignore_functions (config )
287
294
288
295
# Skip any dirs that do not match match_dir
289
296
dirs [:] = [d for d in dirs if match_dir (d )]
@@ -296,18 +303,22 @@ def _get_property_decorators(conf):
296
303
list (config .checked_codes ),
297
304
ignore_decorators ,
298
305
property_decorators ,
306
+ ignore_functions ,
299
307
)
300
308
else :
301
309
config = self ._get_config (os .path .abspath (name ))
302
310
match , _ = _get_matches (config )
303
311
ignore_decorators = _get_ignore_decorators (config )
304
312
property_decorators = _get_property_decorators (config )
313
+ ignore_functions = _get_ignore_functions (config )
314
+
305
315
if match (os .path .basename (name )):
306
316
yield (
307
317
name ,
308
318
list (config .checked_codes ),
309
319
ignore_decorators ,
310
320
property_decorators ,
321
+ ignore_functions ,
311
322
)
312
323
313
324
# --------------------------- Private Methods -----------------------------
@@ -509,6 +520,7 @@ def _merge_configuration(self, parent_config, child_options):
509
520
'match_dir' ,
510
521
'ignore_decorators' ,
511
522
'property_decorators' ,
523
+ 'ignore_functions' ,
512
524
):
513
525
kwargs [key ] = getattr (child_options , key ) or getattr (
514
526
parent_config , key
@@ -548,6 +560,7 @@ def _create_check_config(cls, options, use_defaults=True):
548
560
'match_dir' : "MATCH_DIR_RE" ,
549
561
'ignore_decorators' : "IGNORE_DECORATORS_RE" ,
550
562
'property_decorators' : "PROPERTY_DECORATORS" ,
563
+ 'ignore_functions' : "IGNORE_FUNCTIONS_RE" ,
551
564
}
552
565
for key , default in defaults .items ():
553
566
kwargs [key ] = (
@@ -780,9 +793,10 @@ def _create_option_parser(cls):
780
793
OptionGroup (
781
794
parser ,
782
795
'Note' ,
783
- 'When using --match, --match-dir or --ignore-decorators consider '
784
- 'whether you should use a single quote (\' ) or a double quote ("), '
785
- 'depending on your OS, Shell, etc.' ,
796
+ 'When using --match, --match-dir, --ignore-decorators or '
797
+ '--ignore-functions consider whether you should use a single '
798
+ 'quote (\' ) or a double quote ("), depending on your OS, '
799
+ 'Shell, etc.' ,
786
800
)
787
801
)
788
802
@@ -899,6 +913,19 @@ def _create_option_parser(cls):
899
913
),
900
914
)
901
915
916
+ # Function selection
917
+ option (
918
+ '--ignore-functions' ,
919
+ metavar = '<functions>' ,
920
+ default = None ,
921
+ help = (
922
+ "ignore any functions or methods whose names fit "
923
+ "the <functions> regular expression; default is "
924
+ "--ignore-functions='{}' which does not ignore any "
925
+ "functions." .format (cls .DEFAULT_IGNORE_DECORATORS_RE )
926
+ ),
927
+ )
928
+
902
929
return parser
903
930
904
931
@@ -911,6 +938,7 @@ def _create_option_parser(cls):
911
938
'match_dir' ,
912
939
'ignore_decorators' ,
913
940
'property_decorators' ,
941
+ 'ignore_functions' ,
914
942
),
915
943
)
916
944
0 commit comments