Skip to content

Commit d6b6aee

Browse files
committed
refactor(numpydoc.py): Changed numpydoc_validation_exclue_files sphinx option to use inspect, and simplified path checking using __file__
1 parent 69f23fc commit d6b6aee

File tree

1 file changed

+9
-23
lines changed

1 file changed

+9
-23
lines changed

numpydoc/numpydoc.py

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -196,29 +196,15 @@ def mangle_docstrings(app: SphinxApp, what, name, obj, options, lines):
196196
# numpydoc_validation_exclude_files
197197
if app.config.numpydoc_validation_exclude_files:
198198
excluder = app.config.numpydoc_validation_files_excluder
199-
module = getattr(obj, "__module__", None)
200-
if module:
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):
220-
# Skip validation for this object.
221-
return
199+
module = inspect.getmodule(obj)
200+
try:
201+
path = module.__file__ if module else None
202+
except AttributeError:
203+
path = None
204+
205+
if path and excluder and excluder.search(path):
206+
# Skip validation for this object.
207+
return
222208

223209
try:
224210
doc = get_doc_object(

0 commit comments

Comments
 (0)