Skip to content

Commit e151f0d

Browse files
DOC: fixes classes decorated with set_module not showing its source on numpy's documentation (numpy#28629) (numpy#28645)
* DOC: store file with set_module in classes avoid calling stdlib module inspect TST: adds tests for set_module decorator DOC: adds __file__ attribute to classes decorated with set_module simplify set_module and change attribute name DOC : sets __module_file__ when overriding a __module__ in classes Specity Exceptions fix lint error * rename variable * fix variable name * fix path
1 parent 3d01f64 commit e151f0d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

doc/source/conf.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,7 @@ def _get_c_source_file(obj):
507507
# todo: come up with a better way to generate these
508508
return None
509509

510-
511-
def linkcode_resolve(domain, info):
510+
def linkcode_resolve(domain, info):
512511
"""
513512
Determine the URL corresponding to Python object
514513
"""
@@ -545,6 +544,11 @@ def linkcode_resolve(domain, info):
545544
if isinstance(obj, type) and obj.__module__ == 'numpy':
546545
fn = _get_c_source_file(obj)
547546

547+
# This can be removed when removing the decorator set_module. Fix issue #28629
548+
if hasattr(obj, '_module_file'):
549+
fn = obj._module_file
550+
fn = relpath(fn, start=dirname(numpy.__file__))
551+
548552
if fn is None:
549553
try:
550554
fn = inspect.getsourcefile(obj)

numpy/_utils/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"""
1010

1111
import functools
12+
import sys
1213
import warnings
1314
from ._convertions import asunicode, asbytes
1415

@@ -26,6 +27,12 @@ def example():
2627
"""
2728
def decorator(func):
2829
if module is not None:
30+
if isinstance(func, type):
31+
try:
32+
func._module_file = sys.modules.get(func.__module__).__file__
33+
except (AttributeError, KeyError):
34+
pass
35+
2936
func.__module__ = module
3037
return func
3138
return decorator

0 commit comments

Comments
 (0)