Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GitHub source code links for decorated functions #17

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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