Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion numpydoc/docscrape_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def _process_param(self, param, desc, fake_autosummary):
if prefix:
link_prefix = f"{prefix}."
else:
link_prefix = ""
# leading dot: resolve in the class scope before the module scope
link_prefix = "."

# Referenced object has a docstring
display_param = f":obj:`{param} <{link_prefix}{param}>`"
Expand Down
35 changes: 30 additions & 5 deletions numpydoc/tests/test_docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ def no_period(self):
* hello
* world

:obj:`an_attribute <an_attribute>` : float
:obj:`an_attribute <.an_attribute>` : float
Test attribute

**no_docstring** : str
Expand All @@ -1362,13 +1362,13 @@ def no_period(self):
**no_docstring2** : str
..

:obj:`multiline_sentence <multiline_sentence>`
:obj:`multiline_sentence <.multiline_sentence>`
This is a sentence.

:obj:`midword_period <midword_period>`
:obj:`midword_period <.midword_period>`
The sentence for numpy.org.

:obj:`no_period <no_period>`
:obj:`no_period <.no_period>`
This does not have a period

.. rubric:: Methods
Expand Down Expand Up @@ -1415,7 +1415,7 @@ def an_attribute(self):

attr_doc = """:Attributes:

:obj:`an_attribute <an_attribute>`
:obj:`an_attribute <.an_attribute>`
Test attribute"""

assert attr_doc in str(SphinxClassDoc(Foo))
Expand All @@ -1433,6 +1433,31 @@ def an_attribute(self):
assert "Another description" not in str(SphinxClassDoc(Foo, config=cfg))


def test_attribute_link_is_class_scoped():
class Foo:
"""
Class docstring.

Attributes
----------
identity
Another description that is not used.

"""

@property
def identity(self):
"""Test attribute"""
return

attr_doc = """:Attributes:

:obj:`identity <.identity>`
Test attribute"""

assert attr_doc in str(SphinxClassDoc(Foo))


def test_templated_sections():
doc = SphinxClassDoc(
None,
Expand Down
Loading