Merge pull request #7515 from tk0miya/2044_defvalue_for_ivars

Close #2044: autodoc: Suppress default value for instance attributes
This commit is contained in:
Takeshi KOMIYA 2020-04-23 21:57:34 +09:00 committed by GitHub
commit f565a44981
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 12 deletions

View File

@ -29,6 +29,7 @@ Features added
:confval:`suppress_warnings` :confval:`suppress_warnings`
* C, added scope control directives, :rst:dir:`c:namespace`, * C, added scope control directives, :rst:dir:`c:namespace`,
:rst:dir:`c:namespace-push`, and :rst:dir:`c:namespace-pop`. :rst:dir:`c:namespace-push`, and :rst:dir:`c:namespace-pop`.
* #2044: autodoc: Suppress default value for instance attributes
* #7466: autosummary: headings in generated documents are not translated * #7466: autosummary: headings in generated documents are not translated
* #7490: autosummary: Add ``:caption:`` option to autosummary directive to set a * #7490: autosummary: Add ``:caption:`` option to autosummary directive to set a
caption to the toctree caption to the toctree

View File

@ -66,6 +66,7 @@ def identity(x: Any) -> Any:
ALL = object() ALL = object()
UNINITIALIZED_ATTR = object()
INSTANCEATTR = object() INSTANCEATTR = object()
SLOTSATTR = object() SLOTSATTR = object()
@ -1351,8 +1352,11 @@ class DataDocumenter(ModuleLevelDocumenter):
sourcename) sourcename)
try: try:
objrepr = object_description(self.object) if self.object is UNINITIALIZED_ATTR:
self.add_line(' :value: ' + objrepr, sourcename) pass
else:
objrepr = object_description(self.object)
self.add_line(' :value: ' + objrepr, sourcename)
except ValueError: except ValueError:
pass pass
elif self.options.annotation is SUPPRESS: elif self.options.annotation is SUPPRESS:
@ -1393,6 +1397,7 @@ class DataDeclarationDocumenter(DataDocumenter):
"""Never import anything.""" """Never import anything."""
# disguise as a data # disguise as a data
self.objtype = 'data' self.objtype = 'data'
self.object = UNINITIALIZED_ATTR
try: try:
# import module to obtain type annotation # import module to obtain type annotation
self.parent = importlib.import_module(self.modname) self.parent = importlib.import_module(self.modname)
@ -1603,8 +1608,11 @@ class AttributeDocumenter(DocstringStripSignatureMixin, ClassLevelDocumenter):
sourcename) sourcename)
try: try:
objrepr = object_description(self.object) if self.object is INSTANCEATTR:
self.add_line(' :value: ' + objrepr, sourcename) pass
else:
objrepr = object_description(self.object)
self.add_line(' :value: ' + objrepr, sourcename)
except ValueError: except ValueError:
pass pass
elif self.options.annotation is SUPPRESS: elif self.options.annotation is SUPPRESS:
@ -1675,6 +1683,7 @@ class InstanceAttributeDocumenter(AttributeDocumenter):
"""Never import anything.""" """Never import anything."""
# disguise as an attribute # disguise as an attribute
self.objtype = 'attribute' self.objtype = 'attribute'
self.object = INSTANCEATTR
self._datadescriptor = False self._datadescriptor = False
return True return True

View File

@ -1032,14 +1032,12 @@ def test_instance_attributes(app):
'', '',
' .. py:attribute:: InstAttCls.ia1', ' .. py:attribute:: InstAttCls.ia1',
' :module: target', ' :module: target',
' :value: None',
'', '',
' Doc comment for instance attribute InstAttCls.ia1', ' Doc comment for instance attribute InstAttCls.ia1',
'', '',
'', '',
' .. py:attribute:: InstAttCls.ia2', ' .. py:attribute:: InstAttCls.ia2',
' :module: target', ' :module: target',
' :value: None',
'', '',
' Docstring for instance attribute InstAttCls.ia2.', ' Docstring for instance attribute InstAttCls.ia2.',
'' ''
@ -1066,7 +1064,6 @@ def test_instance_attributes(app):
'', '',
' .. py:attribute:: InstAttCls.ia1', ' .. py:attribute:: InstAttCls.ia1',
' :module: target', ' :module: target',
' :value: None',
'', '',
' Doc comment for instance attribute InstAttCls.ia1', ' Doc comment for instance attribute InstAttCls.ia1',
'' ''
@ -1485,7 +1482,6 @@ def test_autodoc_typed_instance_variables(app):
' .. py:attribute:: Class.attr2', ' .. py:attribute:: Class.attr2',
' :module: target.typed_vars', ' :module: target.typed_vars',
' :type: int', ' :type: int',
' :value: None',
'', '',
'', '',
' .. py:attribute:: Class.attr3', ' .. py:attribute:: Class.attr3',
@ -1497,7 +1493,6 @@ def test_autodoc_typed_instance_variables(app):
' .. py:attribute:: Class.attr4', ' .. py:attribute:: Class.attr4',
' :module: target.typed_vars', ' :module: target.typed_vars',
' :type: int', ' :type: int',
' :value: None',
'', '',
' attr4', ' attr4',
'', '',
@ -1505,7 +1500,6 @@ def test_autodoc_typed_instance_variables(app):
' .. py:attribute:: Class.attr5', ' .. py:attribute:: Class.attr5',
' :module: target.typed_vars', ' :module: target.typed_vars',
' :type: int', ' :type: int',
' :value: None',
'', '',
' attr5', ' attr5',
'', '',
@ -1513,7 +1507,6 @@ def test_autodoc_typed_instance_variables(app):
' .. py:attribute:: Class.attr6', ' .. py:attribute:: Class.attr6',
' :module: target.typed_vars', ' :module: target.typed_vars',
' :type: int', ' :type: int',
' :value: None',
'', '',
' attr6', ' attr6',
'', '',
@ -1529,7 +1522,6 @@ def test_autodoc_typed_instance_variables(app):
'.. py:data:: attr2', '.. py:data:: attr2',
' :module: target.typed_vars', ' :module: target.typed_vars',
' :type: str', ' :type: str',
' :value: None',
'', '',
' attr2', ' attr2',
'', '',