Skip to content

Commit

Permalink
Fix GitHub source code links for decorated functions (#33) (#36)
Browse files Browse the repository at this point in the history
Co-authored-by: Eric Arellano <[email protected]>
(cherry picked from commit b087703)

Co-authored-by: Jim Garrison <[email protected]>
  • Loading branch information
mergify[bot] and garrison authored Oct 10, 2024
1 parent a5d9803 commit 51e9c8f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,26 @@ def linkcode_resolve(domain, info):
if module is None or "qiskit_addon_dice_solver" not in module_name:
return None

def is_valid_code_object(obj):
return (
inspect.isclass(obj) or inspect.ismethod(obj) or inspect.isfunction(obj)
)

obj = module
for part in info["fullname"].split("."):
try:
obj = getattr(obj, part)
except AttributeError:
return None
is_valid_code_object = (
inspect.isclass(obj) or inspect.ismethod(obj) or inspect.isfunction(obj)
)
if not is_valid_code_object:
if not is_valid_code_object(obj):
return None

# Unwrap decorators. This requires they used `functools.wrap()`.
while hasattr(obj, "__wrapped__"):
obj = getattr(obj, "__wrapped__")
if not is_valid_code_object(obj):
return None

try:
full_file_name = inspect.getsourcefile(obj)
except TypeError:
Expand Down

0 comments on commit 51e9c8f

Please sign in to comment.