Skip to content

Commit 6cc4419

Browse files
committed
Link to subclass documentation (#68)
1 parent 851e6c2 commit 6cc4419

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

docs/src/release_notes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ These release notes are based on
88
sphinx-codeautolink adheres to
99
`Semantic Versioning <https://semver.org>`_.
1010

11+
Unreleased
12+
----------
13+
- Add ability to link to subclass documentation (:issue:`68`)
14+
1115
0.6.0 (2021-11-21)
1216
------------------
1317
- Remove text decoration from produced links (:issue:`3`)

src/sphinx_codeautolink/extension/resolve.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def locate_type(
3131
remaining = components[index:]
3232
location = '.'.join(components[:index])
3333

34+
prev_val = None
3435
for component in remaining:
3536
value = getattr(value, component, None)
3637
location += '.' + component
@@ -44,6 +45,14 @@ def locate_type(
4445
# Odd construct encountered: don't try to be clever but continue
4546
pass
4647

48+
if isinstance(prev_val, type) and location not in inventory:
49+
for val in prev_val.mro():
50+
loc = fully_qualified_name(val) + '.' + component
51+
if loc in inventory:
52+
return locate_type(tuple(loc.split('.')), inventory, ends_with_call)
53+
54+
prev_val = value
55+
4756
# A possible function / method call needs to be last in the chain.
4857
# Otherwise we might follow return types on function attribute access.
4958
if (
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
test_project
2+
test_project.Child.meth
3+
test_project.Child
4+
meth
5+
test_project.Child.attr
6+
test_project.Child
7+
attr
8+
# split
9+
# split
10+
Test project
11+
============
12+
13+
.. code:: python
14+
15+
import test_project
16+
test_project.Child.meth()
17+
test_project.Child().meth()
18+
test_project.Child.attr
19+
test_project.Child().attr
20+
21+
.. automodule:: test_project
22+
:no-inherited-members:

tests/extension/src/test_project/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ def optional() -> Optional[Foo]:
3333

3434
def compile():
3535
"""Shadows built in compile function."""
36+
37+
38+
class Child(Foo):
39+
"""Foo child class."""

0 commit comments

Comments
 (0)