@@ -174,21 +174,26 @@ def mangle_docstrings(app, what, name, obj, options, lines):
174
174
logger .error ('[numpydoc] While processing docstring for %r' , name )
175
175
raise
176
176
177
- # TODO: validation only applies to non-module docstrings?
178
177
if app .config .numpydoc_validate :
179
- # TODO: Currently, all validation checks are run and only those
180
- # selected via config are reported. It would be more efficient to
181
- # only run the selected checks.
182
- errors = validate (doc )["errors" ]
183
- if {err [0 ] for err in errors } & app .config .numpydoc_validation_checks :
184
- msg = (
185
- f"[numpydoc] Validation warnings while processing "
186
- f"docstring for { name !r} :\n "
187
- )
188
- for err in errors :
189
- if err [0 ] in app .config .numpydoc_validation_checks :
190
- msg += f" { err [0 ]} : { err [1 ]} \n "
191
- logger .warning (msg )
178
+ # If the user has supplied patterns to ignore via the
179
+ # numpydoc_validation_exclude config option, skip validation for
180
+ # any objs whose name matches any of the patterns
181
+ excluder = app .config .numpydoc_validation_exclude
182
+ exclude_from_validation = excluder .search (name ) if excluder else False
183
+ if not exclude_from_validation :
184
+ # TODO: Currently, all validation checks are run and only those
185
+ # selected via config are reported. It would be more efficient to
186
+ # only run the selected checks.
187
+ errors = validate (doc )["errors" ]
188
+ if {err [0 ] for err in errors } & app .config .numpydoc_validation_checks :
189
+ msg = (
190
+ f"[numpydoc] Validation warnings while processing "
191
+ f"docstring for { name !r} :\n "
192
+ )
193
+ for err in errors :
194
+ if err [0 ] in app .config .numpydoc_validation_checks :
195
+ msg += f" { err [0 ]} : { err [1 ]} \n "
196
+ logger .warning (msg )
192
197
193
198
194
199
if (app .config .numpydoc_edit_link and hasattr (obj , '__name__' ) and
@@ -274,6 +279,7 @@ def setup(app, get_doc_object_=get_doc_object):
274
279
app .add_config_value ('numpydoc_xref_ignore' , set (), True )
275
280
app .add_config_value ('numpydoc_validate' , False , True )
276
281
app .add_config_value ('numpydoc_validation_checks' , set (), True )
282
+ app .add_config_value ('numpydoc_validation_exclude' , set (), False )
277
283
278
284
# Extra mangling domains
279
285
app .add_domain (NumpyPythonDomain )
@@ -312,6 +318,18 @@ def update_config(app, config=None):
312
318
f"config value: { invalid_error_codes } "
313
319
)
314
320
321
+ # Generate the regexp for docstrings to ignore during validation
322
+ if isinstance (config .numpydoc_validation_exclude , str ):
323
+ raise ValueError (
324
+ f"numpydoc_validation_exclude must be a container of strings, "
325
+ f"e.g. [{ config .numpydoc_validation_exclude !r} ]."
326
+ )
327
+ if config .numpydoc_validation_exclude :
328
+ exclude_expr = re .compile (
329
+ r"|" .join (exp for exp in config .numpydoc_validation_exclude )
330
+ )
331
+ config .numpydoc_validation_exclude = exclude_expr
332
+
315
333
316
334
# ------------------------------------------------------------------------------
317
335
# Docstring-mangling domains
0 commit comments