File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -667,6 +667,10 @@ def linkcode_resolve(domain, info) -> str | None:
667667 except AttributeError :
668668 return None
669669
670+ if isinstance (obj , type ):
671+ if hasattr (obj , "_module_source" ):
672+ obj .__module__ , obj ._module_source = obj ._module_source , obj .__module__
673+
670674 try :
671675 fn = inspect .getsourcefile (inspect .unwrap (obj ))
672676 except TypeError :
@@ -694,6 +698,9 @@ def linkcode_resolve(domain, info) -> str | None:
694698
695699 fn = os .path .relpath (fn , start = os .path .dirname (pandas .__file__ ))
696700
701+ if isinstance (obj , type ) and hasattr (obj , "_module_source" ):
702+ obj .__module__ , obj ._module_source = obj ._module_source , obj .__module__
703+
697704 if "+" in version :
698705 return f"https://github.com/pandas-dev/pandas/blob/main/pandas/{ fn } { linespec } "
699706 else :
Original file line number Diff line number Diff line change @@ -526,7 +526,15 @@ def example():
526526
527527 def decorator (func : F ) -> F :
528528 if module is not None :
529+ if isinstance (func , type ):
530+ # Store the original module for classes to ensure linkcode_resolve
531+ # can resolve the true source location after re-exporting
532+ try :
533+ func ._module_source = func .__module__ # type: ignore[attr-defined]
534+ except AttributeError :
535+ pass
536+
529537 func .__module__ = module
530- return func
538+ return cast ( "F" , func ) # type: ignore[redundant-cast]
531539
532540 return decorator
You can’t perform that action at this time.
0 commit comments