Skip to content

Commit 69f23fc

Browse files
committed
fix(numpydoc.py): Corrected module path check for numpydoc_validation_exclude_files option
1 parent 2e09ea6 commit 69f23fc

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

numpydoc/numpydoc.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import itertools
2323
import pydoc
2424
import re
25+
import sys
2526
from collections.abc import Callable
2627
from copy import deepcopy
2728

@@ -197,10 +198,25 @@ def mangle_docstrings(app: SphinxApp, what, name, obj, options, lines):
197198
excluder = app.config.numpydoc_validation_files_excluder
198199
module = getattr(obj, "__module__", None)
199200
if module:
200-
# Perform the exclusion check solely on the module if there's no __path__.
201-
path = getattr(obj, "__path__", module)
202-
exclude_from_validation = excluder.search(path) if excluder else False
203-
if exclude_from_validation:
201+
# Check if module is a string
202+
if isinstance(module, str):
203+
if module in sys.modules:
204+
module_obj = sys.modules[module]
205+
path = (
206+
module_obj.__file__
207+
if hasattr(module_obj, "__file__")
208+
else None
209+
)
210+
else:
211+
# Just filter the module string as the path.
212+
path = module
213+
# Check if module is module instance:
214+
elif module.__class__.__name__ == "module":
215+
path = getattr(module, "__path__", None)
216+
else:
217+
path = None
218+
219+
if path and excluder and excluder.search(path):
204220
# Skip validation for this object.
205221
return
206222

numpydoc/tests/test_numpydoc.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def test_clean_backrefs():
299299
),
300300
(
301301
[
302-
r"^test_numpydoc$",
302+
r"^.*test_numpydoc\.py$",
303303
],
304304
False,
305305
),
@@ -329,7 +329,6 @@ def process_something_noop_function():
329329
logging.setup(app, status, warning)
330330

331331
# Simulate a file that matches the exclude pattern
332-
docname = "test_numpydoc"
333332
mangle_docstrings(
334333
app,
335334
"function",

0 commit comments

Comments
 (0)