mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix: autodoc class __init__ override not removed from docstring. Closes #1138
This commit is contained in:
parent
4fd9d846d6
commit
1d5c7d1f20
4
CHANGES
4
CHANGES
@ -34,6 +34,10 @@ Bugs fixed
|
||||
|
||||
* #1269: Fix ResourceWarnings with Python 3.2 or later.
|
||||
|
||||
* #1138: Fix: When ``autodoc_docstring_signature = True`` and
|
||||
``autoclass_content = 'init'`` or ``'both'``, __init__ line should be
|
||||
removed from class documentation.
|
||||
|
||||
|
||||
Release 1.2 beta3 (released Oct 3, 2013)
|
||||
========================================
|
||||
|
@ -1071,8 +1071,18 @@ class ClassDocumenter(ModuleLevelDocumenter):
|
||||
# for classes, what the "docstring" is can be controlled via a
|
||||
# config value; the default is only the class docstring
|
||||
if content in ('both', 'init'):
|
||||
initdocstring = self.get_attr(
|
||||
self.get_attr(self.object, '__init__', None), '__doc__')
|
||||
# get __init__ method document from __init__.__doc__
|
||||
if self.env.config.autodoc_docstring_signature:
|
||||
# only act if the feature is enabled
|
||||
init_doc = MethodDocumenter(self.directive, '__init__')
|
||||
init_doc.object = self.get_attr(self.object, '__init__', None)
|
||||
init_doc.objpath = ['__init__']
|
||||
init_doc._find_signature() # this effects to get_doc() result
|
||||
initdocstring = '\n'.join(
|
||||
['\n'.join(l) for l in init_doc.get_doc(encoding)])
|
||||
else:
|
||||
initdocstring = self.get_attr(
|
||||
self.get_attr(self.object, '__init__', None), '__doc__')
|
||||
# for new-style classes, no __init__ means default __init__
|
||||
if initdocstring == object.__init__.__doc__:
|
||||
initdocstring = None
|
||||
|
@ -301,6 +301,39 @@ def test_get_doc():
|
||||
assert getdocl('class', D) == ['Class docstring', '', 'Init docstring',
|
||||
'', 'Other', ' lines']
|
||||
|
||||
#__init__ have signature at first line of docstring
|
||||
class E:
|
||||
"""Class docstring"""
|
||||
def __init__(self, *args, **kw):
|
||||
"""
|
||||
__init__(a1, a2, kw1=True, kw2=False)
|
||||
|
||||
Init docstring
|
||||
"""
|
||||
|
||||
# signature line in the docstring will be kept when
|
||||
# autodoc_docstring_signature == False
|
||||
directive.env.config.autodoc_docstring_signature = False
|
||||
directive.env.config.autoclass_content = 'class'
|
||||
assert getdocl('class', E) == ['Class docstring']
|
||||
directive.env.config.autoclass_content = 'init'
|
||||
assert getdocl('class', E) == ['__init__(a1, a2, kw1=True, kw2=False)',
|
||||
'', 'Init docstring']
|
||||
directive.env.config.autoclass_content = 'both'
|
||||
assert getdocl('class', E) == ['Class docstring', '',
|
||||
'__init__(a1, a2, kw1=True, kw2=False)',
|
||||
'', 'Init docstring']
|
||||
|
||||
# signature line in the docstring will be removed when
|
||||
# autodoc_docstring_signature == True
|
||||
directive.env.config.autodoc_docstring_signature = True #default
|
||||
directive.env.config.autoclass_content = 'class'
|
||||
assert getdocl('class', E) == ['Class docstring']
|
||||
directive.env.config.autoclass_content = 'init'
|
||||
assert getdocl('class', E) == ['Init docstring']
|
||||
directive.env.config.autoclass_content = 'both'
|
||||
assert getdocl('class', E) == ['Class docstring', '', 'Init docstring']
|
||||
|
||||
|
||||
@with_setup(setup_test)
|
||||
def test_docstring_processing():
|
||||
|
Loading…
Reference in New Issue
Block a user