Skip to content

Commit e2a0de4

Browse files
committed
Add linkcode links for properties and cached properties
1 parent 07ceb77 commit e2a0de4

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

sphinx_github_style/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import inspect
55
import subprocess
66
from pathlib import Path
7+
from functools import cached_property
78
from sphinx.application import Sphinx
89
from sphinx.errors import ExtensionError
910
from typing import Dict, Any, Optional, Callable
@@ -191,6 +192,11 @@ def linkcode_resolve(domain, info):
191192
except AttributeError:
192193
return None
193194

195+
if isinstance(obj, property):
196+
obj = obj.fget
197+
elif isinstance(obj, cached_property):
198+
obj = obj.func
199+
194200
try:
195201
modpath = inspect.getsourcefile(inspect.unwrap(obj))
196202
filepath = Path(modpath).relative_to(repo_dir)
@@ -201,10 +207,10 @@ def linkcode_resolve(domain, info):
201207

202208
try:
203209
source, lineno = inspect.getsourcelines(obj)
204-
except OSError:
210+
except Exception:
205211
return None
206-
else:
207-
linestart, linestop = lineno, lineno + len(source) - 1
212+
213+
linestart, linestop = lineno, lineno + len(source) - 1
208214

209215
# Example: https://github.com/TDKorn/my-magento/blob/docs/magento/models/model.py#L28-L59
210216
final_link = linkcode_url.format(

0 commit comments

Comments
 (0)