Skip to content

Commit

Permalink
Fix GitHub source code links for decorated functions (#17)
Browse files Browse the repository at this point in the history
* Fix GitHub source code links for decorated functions

* style updates

---------

Co-authored-by: Eric Arellano <[email protected]>
(cherry picked from commit c3c4ee9)
  • Loading branch information
garrison authored and mergify[bot] committed Oct 21, 2024
1 parent e9b91ee commit 0be56b2
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,24 @@ def linkcode_resolve(domain, info):
if module is None or "qiskit_addon_mpf" 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 = 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 0be56b2

Please sign in to comment.