mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #7136 from tk0miya/5673_nested_classes
Fix incorrect handling of nested class names
This commit is contained in:
commit
5018422db3
2
CHANGES
2
CHANGES
@ -58,6 +58,8 @@ Bugs fixed
|
|||||||
declarations.
|
declarations.
|
||||||
* C++, suppress warnings for directly dependent typenames in cross references
|
* C++, suppress warnings for directly dependent typenames in cross references
|
||||||
generated automatically in signatures.
|
generated automatically in signatures.
|
||||||
|
* #5637: autodoc: Incorrect handling of nested class names on show-inheritance
|
||||||
|
* #5637: inheritance_diagram: Incorrect handling of nested class names
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
@ -1146,7 +1146,7 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type:
|
|||||||
if hasattr(self.object, '__bases__') and len(self.object.__bases__):
|
if hasattr(self.object, '__bases__') and len(self.object.__bases__):
|
||||||
bases = [':class:`%s`' % b.__name__
|
bases = [':class:`%s`' % b.__name__
|
||||||
if b.__module__ in ('__builtin__', 'builtins')
|
if b.__module__ in ('__builtin__', 'builtins')
|
||||||
else ':class:`%s.%s`' % (b.__module__, b.__name__)
|
else ':class:`%s.%s`' % (b.__module__, b.__qualname__)
|
||||||
for b in self.object.__bases__]
|
for b in self.object.__bases__]
|
||||||
self.add_line(' ' + _('Bases: %s') % ', '.join(bases),
|
self.add_line(' ' + _('Bases: %s') % ', '.join(bases),
|
||||||
sourcename)
|
sourcename)
|
||||||
|
@ -229,7 +229,7 @@ class InheritanceGraph:
|
|||||||
if module in ('__builtin__', 'builtins'):
|
if module in ('__builtin__', 'builtins'):
|
||||||
fullname = cls.__name__
|
fullname = cls.__name__
|
||||||
else:
|
else:
|
||||||
fullname = '%s.%s' % (module, cls.__name__)
|
fullname = '%s.%s' % (module, cls.__qualname__)
|
||||||
if parts == 0:
|
if parts == 0:
|
||||||
result = fullname
|
result = fullname
|
||||||
else:
|
else:
|
||||||
|
@ -110,6 +110,10 @@ class Outer(object):
|
|||||||
factory = dict
|
factory = dict
|
||||||
|
|
||||||
|
|
||||||
|
class InnerChild(Outer.Inner):
|
||||||
|
"""InnerChild docstring"""
|
||||||
|
|
||||||
|
|
||||||
class DocstringSig(object):
|
class DocstringSig(object):
|
||||||
def meth(self):
|
def meth(self):
|
||||||
"""meth(FOO, BAR=1) -> BAZ
|
"""meth(FOO, BAR=1) -> BAZ
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
Diagram with Nested Classes
|
||||||
|
===========================
|
||||||
|
|
||||||
|
.. inheritance-diagram::
|
||||||
|
dummy.test_nested
|
12
tests/roots/test-inheritance/dummy/test_nested.py
Normal file
12
tests/roots/test-inheritance/dummy/test_nested.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
"""
|
||||||
|
Test with nested classes.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class A(object):
|
||||||
|
class B(object):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class C(A.B):
|
||||||
|
pass
|
@ -685,6 +685,7 @@ def test_autodoc_ignore_module_all(app):
|
|||||||
assert list(filter(lambda l: 'class::' in l, actual)) == [
|
assert list(filter(lambda l: 'class::' in l, actual)) == [
|
||||||
'.. py:class:: Class(arg)',
|
'.. py:class:: Class(arg)',
|
||||||
'.. py:class:: CustomDict',
|
'.. py:class:: CustomDict',
|
||||||
|
'.. py:class:: InnerChild',
|
||||||
'.. py:class:: InstAttCls()',
|
'.. py:class:: InstAttCls()',
|
||||||
'.. py:class:: Outer',
|
'.. py:class:: Outer',
|
||||||
' .. py:class:: Outer.Inner',
|
' .. py:class:: Outer.Inner',
|
||||||
@ -775,6 +776,18 @@ def test_autodoc_inner_class(app):
|
|||||||
' ',
|
' ',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
options['show-inheritance'] = True
|
||||||
|
actual = do_autodoc(app, 'class', 'target.InnerChild', options)
|
||||||
|
assert list(actual) == [
|
||||||
|
'',
|
||||||
|
'.. py:class:: InnerChild',
|
||||||
|
' :module: target', '',
|
||||||
|
' Bases: :class:`target.Outer.Inner`',
|
||||||
|
'',
|
||||||
|
' InnerChild docstring',
|
||||||
|
' '
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
||||||
def test_autodoc_classmethod(app):
|
def test_autodoc_classmethod(app):
|
||||||
|
@ -132,6 +132,14 @@ def test_inheritance_diagram(app, status, warning):
|
|||||||
('dummy.test.A', 'dummy.test.A', [], None),
|
('dummy.test.A', 'dummy.test.A', [], None),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# inheritance diagram involving a base class nested within another class
|
||||||
|
for cls in graphs['diagram_w_nested_classes'].class_info:
|
||||||
|
assert cls in [
|
||||||
|
('dummy.test_nested.A', 'dummy.test_nested.A', [], None),
|
||||||
|
('dummy.test_nested.C', 'dummy.test_nested.C', ['dummy.test_nested.A.B'], None),
|
||||||
|
('dummy.test_nested.A.B', 'dummy.test_nested.A.B', [], None)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('html', testroot='ext-inheritance_diagram')
|
@pytest.mark.sphinx('html', testroot='ext-inheritance_diagram')
|
||||||
@pytest.mark.usefixtures('if_graphviz_found')
|
@pytest.mark.usefixtures('if_graphviz_found')
|
||||||
|
Loading…
Reference in New Issue
Block a user