Skip to content

Commit 51bcea6

Browse files
committed
Extract check selection logic from sphinx side into utility function.
1 parent 894c8c4 commit 51bcea6

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

numpydoc/numpydoc.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
raise RuntimeError("Sphinx 5 or newer is required")
3535

3636
from .docscrape_sphinx import get_doc_object
37+
from .utils import get_validation_checks
3738
from .validate import validate, ERROR_MSGS
3839
from .xref import DEFAULT_LINKS
3940
from . import __version__
@@ -310,17 +311,9 @@ def update_config(app, config=None):
310311

311312
# Processing to determine whether numpydoc_validation_checks is treated
312313
# as a blocklist or allowlist
313-
valid_error_codes = set(ERROR_MSGS.keys())
314-
if "all" in config.numpydoc_validation_checks:
315-
block = deepcopy(config.numpydoc_validation_checks)
316-
config.numpydoc_validation_checks = valid_error_codes - block
317-
# Ensure that the validation check set contains only valid error codes
318-
invalid_error_codes = config.numpydoc_validation_checks - valid_error_codes
319-
if invalid_error_codes:
320-
raise ValueError(
321-
f"Unrecognized validation code(s) in numpydoc_validation_checks "
322-
f"config value: {invalid_error_codes}"
323-
)
314+
config.numpydoc_validation_checks = get_validation_checks(
315+
config.numpydoc_validation_checks
316+
)
324317

325318
# Generate the regexp for docstrings to ignore during validation
326319
if isinstance(config.numpydoc_validation_exclude, str):

numpydoc/utils.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""Utility functions for numpydoc."""
2+
3+
from copy import deepcopy
4+
from typing import Set
5+
6+
from .validate import ERROR_MSGS
7+
8+
9+
def get_validation_checks(validation_checks: Set[str]) -> Set[str]:
10+
"""
11+
Get the set of validation checks to report on.
12+
13+
Parameters
14+
----------
15+
validation_checks : set[str]
16+
A set of validation checks to report on. If the set is ``{"all"}``,
17+
all checks will be reported. If the set contains just specific checks,
18+
only those will be reported on. If the set contains both ``"all"`` and
19+
specific checks, all checks except those included in the set will be
20+
reported on.
21+
22+
Returns
23+
-------
24+
set[str]
25+
The set of validation checks to report on.
26+
"""
27+
# TODO: add tests
28+
valid_error_codes = set(ERROR_MSGS.keys())
29+
if "all" in validation_checks:
30+
block = deepcopy(validation_checks)
31+
validation_checks = valid_error_codes - block
32+
33+
# Ensure that the validation check set contains only valid error codes
34+
invalid_error_codes = validation_checks - valid_error_codes
35+
if invalid_error_codes:
36+
raise ValueError(
37+
f"Unrecognized validation code(s) in numpydoc_validation_checks "
38+
f"config value: {invalid_error_codes}"
39+
)
40+
41+
return validation_checks

0 commit comments

Comments
 (0)