@@ -180,6 +180,7 @@ class ConfigurationParser:
180180 'match' ,
181181 'match-dir' ,
182182 'ignore-decorators' ,
183+ 'ignore-functions' ,
183184 )
184185 BASE_ERROR_SELECTION_OPTIONS = ('ignore' , 'select' , 'convention' )
185186
@@ -189,6 +190,7 @@ class ConfigurationParser:
189190 DEFAULT_PROPERTY_DECORATORS = (
190191 "property,cached_property,functools.cached_property"
191192 )
193+ DEFAULT_IGNORE_FUNCTIONS_RE = ''
192194 DEFAULT_CONVENTION = conventions .pep257
193195
194196 PROJECT_CONFIG_FILES = (
@@ -263,6 +265,10 @@ def _get_matches(conf):
263265 match_dir_func = re (conf .match_dir + '$' ).match
264266 return match_func , match_dir_func
265267
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+
266272 def _get_ignore_decorators (conf ):
267273 """Return the `ignore_decorators` as None or regex."""
268274 return (
@@ -284,6 +290,7 @@ def _get_property_decorators(conf):
284290 match , match_dir = _get_matches (config )
285291 ignore_decorators = _get_ignore_decorators (config )
286292 property_decorators = _get_property_decorators (config )
293+ ignore_functions = _get_ignore_functions (config )
287294
288295 # Skip any dirs that do not match match_dir
289296 dirs [:] = [d for d in dirs if match_dir (d )]
@@ -296,18 +303,22 @@ def _get_property_decorators(conf):
296303 list (config .checked_codes ),
297304 ignore_decorators ,
298305 property_decorators ,
306+ ignore_functions ,
299307 )
300308 else :
301309 config = self ._get_config (os .path .abspath (name ))
302310 match , _ = _get_matches (config )
303311 ignore_decorators = _get_ignore_decorators (config )
304312 property_decorators = _get_property_decorators (config )
313+ ignore_functions = _get_ignore_functions (config )
314+
305315 if match (os .path .basename (name )):
306316 yield (
307317 name ,
308318 list (config .checked_codes ),
309319 ignore_decorators ,
310320 property_decorators ,
321+ ignore_functions ,
311322 )
312323
313324 # --------------------------- Private Methods -----------------------------
@@ -509,6 +520,7 @@ def _merge_configuration(self, parent_config, child_options):
509520 'match_dir' ,
510521 'ignore_decorators' ,
511522 'property_decorators' ,
523+ 'ignore_functions' ,
512524 ):
513525 kwargs [key ] = getattr (child_options , key ) or getattr (
514526 parent_config , key
@@ -548,6 +560,7 @@ def _create_check_config(cls, options, use_defaults=True):
548560 'match_dir' : "MATCH_DIR_RE" ,
549561 'ignore_decorators' : "IGNORE_DECORATORS_RE" ,
550562 'property_decorators' : "PROPERTY_DECORATORS" ,
563+ 'ignore_functions' : "IGNORE_FUNCTIONS_RE" ,
551564 }
552565 for key , default in defaults .items ():
553566 kwargs [key ] = (
@@ -780,9 +793,10 @@ def _create_option_parser(cls):
780793 OptionGroup (
781794 parser ,
782795 '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.' ,
786800 )
787801 )
788802
@@ -899,6 +913,19 @@ def _create_option_parser(cls):
899913 ),
900914 )
901915
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+
902929 return parser
903930
904931
@@ -911,6 +938,7 @@ def _create_option_parser(cls):
911938 'match_dir' ,
912939 'ignore_decorators' ,
913940 'property_decorators' ,
941+ 'ignore_functions' ,
914942 ),
915943)
916944
0 commit comments