Skip to content

Commit 2a7a0d0

Browse files
DOC: Fixes line numbers on classes decorated with set_module (#28629) (#28918)
1 parent b1656d2 commit 2a7a0d0

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
@@ -544,14 +544,14 @@ def linkcode_resolve(domain, info):
544544
fn = None
545545
lineno = None
546546

547-
# Make a poor effort at linking C extension types
548-
if isinstance(obj, type) and obj.__module__ == 'numpy':
549-
fn = _get_c_source_file(obj)
547+
if isinstance(obj, type):
548+
# Make a poor effort at linking C extension types
549+
if obj.__module__ == 'numpy':
550+
fn = _get_c_source_file(obj)
550551

551-
# This can be removed when removing the decorator set_module. Fix issue #28629
552-
if hasattr(obj, '_module_file'):
553-
fn = obj._module_file
554-
fn = relpath(fn, start=dirname(numpy.__file__))
552+
# This can be removed when removing the decorator set_module. Fix issue #28629
553+
if hasattr(obj, '_module_source'):
554+
obj.__module__, obj._module_source = obj._module_source, obj.__module__
555555

556556
if fn is None:
557557
try:
@@ -578,6 +578,9 @@ def linkcode_resolve(domain, info):
578578
else:
579579
linespec = ""
580580

581+
if isinstance(obj, type) and hasattr(obj, '_module_source'):
582+
obj.__module__, obj._module_source = obj._module_source, obj.__module__
583+
581584
if 'dev' in numpy.__version__:
582585
return f"https://github.com/numpy/numpy/blob/main/numpy/{fn}{linespec}"
583586
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

1514
from ._convertions import asbytes, asunicode
@@ -30,8 +29,8 @@ def decorator(func):
3029
if module is not None:
3130
if isinstance(func, type):
3231
try:
33-
func._module_file = sys.modules.get(func.__module__).__file__
34-
except (AttributeError, KeyError):
32+
func._module_source = func.__module__
33+
except (AttributeError):
3534
pass
3635

3736
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