mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
autodoc: make full reference for classes, aliased with "alias of"
We do this here only if class belongs to the different module. Closes sphinx-doc/sphinx#2437
This commit is contained in:
parent
695b9f9e18
commit
b1c100ca3b
2
CHANGES
2
CHANGES
@ -16,6 +16,8 @@ Features added
|
||||
Bugs fixed
|
||||
----------
|
||||
|
||||
* #2437: make full reference for classes, aliased with "alias of"
|
||||
|
||||
Testing
|
||||
--------
|
||||
|
||||
|
@ -1513,8 +1513,14 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type:
|
||||
def add_content(self, more_content, no_docstring=False):
|
||||
# type: (Any, bool) -> None
|
||||
if self.doc_as_attr:
|
||||
classname = safe_getattr(self.object, '__qualname__', None)
|
||||
if not classname:
|
||||
classname = safe_getattr(self.object, '__name__', None)
|
||||
if classname:
|
||||
module = safe_getattr(self.object, '__module__', None)
|
||||
parentmodule = safe_getattr(self.parent, '__module__', None)
|
||||
if module and module != parentmodule:
|
||||
classname = str(module) + u'.' + str(classname)
|
||||
content = ViewList(
|
||||
[_('alias of :class:`%s`') % classname], source='')
|
||||
ModuleLevelDocumenter.add_content(self, content,
|
||||
|
5
tests/roots/test-ext-autodoc/autodoc_dummy_bar.py
Normal file
5
tests/roots/test-ext-autodoc/autodoc_dummy_bar.py
Normal file
@ -0,0 +1,5 @@
|
||||
from bug2437.autodoc_dummy_foo import Foo
|
||||
|
||||
class Bar(object):
|
||||
"""Dummy class Bar with alias."""
|
||||
my_name = Foo
|
0
tests/roots/test-ext-autodoc/bug2437/__init__.py
Normal file
0
tests/roots/test-ext-autodoc/bug2437/__init__.py
Normal file
@ -0,0 +1,3 @@
|
||||
class Foo(object):
|
||||
"""Dummy class Foo."""
|
||||
pass
|
@ -10,3 +10,5 @@ source_suffix = '.rst'
|
||||
autodoc_mock_imports = [
|
||||
'dummy'
|
||||
]
|
||||
|
||||
nitpicky = True
|
||||
|
@ -1,3 +1,9 @@
|
||||
|
||||
.. automodule:: autodoc_dummy_module
|
||||
:members:
|
||||
|
||||
.. automodule:: bug2437.autodoc_dummy_foo
|
||||
:members:
|
||||
|
||||
.. automodule:: autodoc_dummy_bar
|
||||
:members:
|
||||
|
@ -22,3 +22,13 @@ def test_autodoc(app, status, warning):
|
||||
assert isinstance(content[3], addnodes.desc)
|
||||
assert content[3][0].astext() == 'autodoc_dummy_module.test'
|
||||
assert content[3][1].astext() == 'Dummy function using dummy.*'
|
||||
|
||||
# issue sphinx-doc/sphinx#2437
|
||||
assert content[11][-1].astext() == """Dummy class Bar with alias.
|
||||
|
||||
|
||||
|
||||
my_name
|
||||
|
||||
alias of bug2437.autodoc_dummy_foo.Foo"""
|
||||
assert warning.getvalue() == ''
|
||||
|
Loading…
Reference in New Issue
Block a user