Fix #9175: autodoc: Special member is not documented in the module

The special members are not treated as "attributes".  So they're not
handled by DataDocumenter.  This moves the detection to the earlier
step of filter_members().
This commit is contained in:
Takeshi KOMIYA 2021-05-08 15:33:18 +09:00
parent 512743525c
commit d69c35b1a4
4 changed files with 106 additions and 1 deletions

View File

@ -23,6 +23,7 @@ Features added
* #8588: autodoc: :confval:`autodoc_type_aliases` now supports dotted name. It * #8588: autodoc: :confval:`autodoc_type_aliases` now supports dotted name. It
allows you to define an alias for a class with module name like allows you to define an alias for a class with module name like
``foo.bar.BazClass`` ``foo.bar.BazClass``
* #9175: autodoc: Special member is not documented in the module
* #3257: autosummary: Support instance attributes for classes * #3257: autosummary: Support instance attributes for classes
* #9129: html search: Show search summaries when html_copy_source = False * #9129: html search: Show search summaries when html_copy_source = False
* #9120: html theme: Eliminate prompt characters of code-block from copyable * #9120: html theme: Eliminate prompt characters of code-block from copyable

View File

@ -709,6 +709,8 @@ class Documenter:
# if isattr is True, the member is documented as an attribute # if isattr is True, the member is documented as an attribute
if member is INSTANCEATTR: if member is INSTANCEATTR:
isattr = True isattr = True
elif (namespace, membername) in attr_docs:
isattr = True
else: else:
isattr = False isattr = False
@ -769,7 +771,6 @@ class Documenter:
else: else:
# keep documented attributes # keep documented attributes
keep = True keep = True
isattr = True
elif want_all and isprivate: elif want_all and isprivate:
if has_doc or self.options.undoc_members: if has_doc or self.options.undoc_members:
if self.options.private_members is None: if self.options.private_members is None:

View File

@ -0,0 +1,14 @@
undocumented = 1
#: docstring
documented = 1
undoc_annotated: int
#: docstring
annotated: int
__special__ = 1
#: docstring
__documented_special__ = 1

View File

@ -29,6 +29,95 @@ def test_empty_all(app):
] ]
@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_automodule(app):
options = {'members': None}
actual = do_autodoc(app, 'module', 'target.module', options)
assert list(actual) == [
'',
'.. py:module:: target.module',
'',
'',
'.. py:data:: annotated',
' :module: target.module',
' :type: int',
'',
' docstring',
'',
'',
'.. py:data:: documented',
' :module: target.module',
' :value: 1',
'',
' docstring',
'',
]
@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_automodule_undoc_members(app):
options = {'members': None,
'undoc-members': None}
actual = do_autodoc(app, 'module', 'target.module', options)
assert list(actual) == [
'',
'.. py:module:: target.module',
'',
'',
'.. py:data:: annotated',
' :module: target.module',
' :type: int',
'',
' docstring',
'',
'',
'.. py:data:: documented',
' :module: target.module',
' :value: 1',
'',
' docstring',
'',
'',
'.. py:data:: undoc_annotated',
' :module: target.module',
' :type: int',
'',
]
@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_automodule_special_members(app):
options = {'members': None,
'special-members': None}
actual = do_autodoc(app, 'module', 'target.module', options)
assert list(actual) == [
'',
'.. py:module:: target.module',
'',
'',
'.. py:data:: __documented_special__',
' :module: target.module',
' :value: 1',
'',
' docstring',
'',
'',
'.. py:data:: annotated',
' :module: target.module',
' :type: int',
'',
' docstring',
'',
'',
'.. py:data:: documented',
' :module: target.module',
' :value: 1',
'',
' docstring',
'',
]
@pytest.mark.sphinx('html', testroot='ext-autodoc', @pytest.mark.sphinx('html', testroot='ext-autodoc',
confoverrides={'autodoc_mock_imports': ['missing_module', confoverrides={'autodoc_mock_imports': ['missing_module',
'missing_package1', 'missing_package1',