Skip to content

Commit 6ed0ece

Browse files
DOC: Fixes line numbers on classes decorated with set_module (#28629)
1 parent 470c458 commit 6ed0ece

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

doc/source/conf.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -539,14 +539,14 @@ def linkcode_resolve(domain, info):
539539
fn = None
540540
lineno = None
541541

542-
# Make a poor effort at linking C extension types
543-
if isinstance(obj, type) and obj.__module__ == 'numpy':
544-
fn = _get_c_source_file(obj)
542+
if isinstance(obj, type):
543+
# Make a poor effort at linking C extension types
544+
if obj.__module__ == 'numpy':
545+
fn = _get_c_source_file(obj)
545546

546-
# This can be removed when removing the decorator set_module. Fix issue #28629
547-
if hasattr(obj, '_module_file'):
548-
fn = obj._module_file
549-
fn = relpath(fn, start=dirname(numpy.__file__))
547+
# This can be removed when removing the decorator set_module. Fix issue #28629
548+
if hasattr(obj, '_module_source'):
549+
obj.__module__, obj._module_source = obj._module_source, obj.__module__
550550

551551
if fn is None:
552552
try:
@@ -573,6 +573,9 @@ def linkcode_resolve(domain, info):
573573
else:
574574
linespec = ""
575575

576+
if isinstance(obj, type) and hasattr(obj, '_module_source'):
577+
obj.__module__, obj._module_source = obj._module_source, obj.__module__
578+
576579
if 'dev' in numpy.__version__:
577580
return f"https://github.com/numpy/numpy/blob/main/numpy/{fn}{linespec}"
578581
else:

numpy/_utils/__init__.py

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

1111
import functools
12-
import sys
1312
import warnings
1413
from ._convertions import asunicode, asbytes
1514

@@ -29,8 +28,8 @@ def decorator(func):
2928
if module is not None:
3029
if isinstance(func, type):
3130
try:
32-
func._module_file = sys.modules.get(func.__module__).__file__
33-
except (AttributeError, KeyError):
31+
func._module_source = func.__module__
32+
except (AttributeError):
3433
pass
3534

3635
func.__module__ = module

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy