@@ -182,10 +182,12 @@ def _ignore_issue(self, node: ast.AST, check: str) -> bool:
182
182
return True
183
183
184
184
if self .config ["overrides" ]:
185
- if check == "SS05" :
186
- pattern = self .config ["overrides" ]. get ( "SS05" )
187
- if pattern and re .match (pattern , ast .get_docstring (node )) is not None :
185
+ try :
186
+ pattern = self .config ["overrides" ][ check ]
187
+ if re .search (pattern , ast .get_docstring (node )) is not None :
188
188
return True
189
+ except KeyError :
190
+ pass
189
191
190
192
try :
191
193
if check in self .numpydoc_ignore_comments [getattr (node , "lineno" , 1 )]:
@@ -265,6 +267,20 @@ def parse_config(dir_path: os.PathLike = None) -> dict:
265
267
toml_path = dir_path / "pyproject.toml"
266
268
cfg_path = dir_path / "setup.cfg"
267
269
270
+ def compile_regex (expressions ):
271
+ return (
272
+ re .compile (r"|" .join (exp for exp in expressions if exp ))
273
+ if expressions
274
+ else None
275
+ )
276
+
277
+ def extract_check_overrides (options , config_items ):
278
+ for option , value in config_items :
279
+ if option .startswith ("override_" ):
280
+ _ , check = option .split ("_" )
281
+ if value :
282
+ options ["overrides" ][check .upper ()] = compile_regex (value )
283
+
268
284
if toml_path .is_file ():
269
285
with open (toml_path , "rb" ) as toml_file :
270
286
pyproject_toml = tomllib .load (toml_file )
@@ -278,10 +294,8 @@ def parse_config(dir_path: os.PathLike = None) -> dict:
278
294
else [global_exclusions ]
279
295
)
280
296
281
- for check in ["SS05" ]:
282
- regex = config .get (f"override_{ check } " )
283
- if regex :
284
- options ["overrides" ][check ] = re .compile (regex )
297
+ extract_check_overrides (options , config .items ())
298
+
285
299
elif cfg_path .is_file ():
286
300
config = configparser .ConfigParser ()
287
301
config .read (cfg_path )
@@ -305,21 +319,16 @@ def parse_config(dir_path: os.PathLike = None) -> dict:
305
319
)
306
320
except configparser .NoOptionError :
307
321
pass
308
- try :
309
- options ["overrides" ]["SS05" ] = re .compile (
310
- config .get (numpydoc_validation_config_section , "override_SS05" )
311
- )
312
- except configparser .NoOptionError :
313
- pass
322
+
323
+ extract_check_overrides (
324
+ options , config .items (numpydoc_validation_config_section )
325
+ )
326
+
314
327
except configparser .NoSectionError :
315
328
pass
316
329
317
330
options ["checks" ] = get_validation_checks (options ["checks" ])
318
- options ["exclude" ] = (
319
- re .compile (r"|" .join (exp for exp in options ["exclude" ]))
320
- if options ["exclude" ]
321
- else None
322
- )
331
+ options ["exclude" ] = compile_regex (options ["exclude" ])
323
332
return options
324
333
325
334
0 commit comments