Fix #9752: autodoc: Failed to detect type annotation for slots attribute

This commit is contained in:
Takeshi KOMIYA
2021-10-23 14:59:36 +09:00
parent e6f9603494
commit b778ee806e
7 changed files with 22 additions and 3 deletions

View File

@@ -28,6 +28,7 @@ Incompatible changes
Deprecated
----------
* ``sphinx.ext.autodoc.AttributeDocumenter._datadescriptor``
* ``sphinx.writers.html.HTMLTranslator._fieldlist_row_index``
* ``sphinx.writers.html.HTMLTranslator._table_row_index``
* ``sphinx.writers.html5.HTML5Translator._fieldlist_row_index``
@@ -61,6 +62,7 @@ Bugs fixed
* #9607: autodoc: Incorrect base class detection for the subclasses of the
generic class
* #9755: autodoc: memory addresses are shown for aliases
* #9752: autodoc: Failed to detect type annotation for slots attribute
* #9630: autosummary: Failed to build summary table if :confval:`primary_domain`
is not 'py'
* #9670: html: Fix download file with special characters

View File

@@ -22,6 +22,11 @@ The following is a list of deprecated interfaces.
- (will be) Removed
- Alternatives
* - ``sphinx.ext.autodoc.AttributeDocumenter._datadescriptor``
- 4.3
- 6.0
- N/A
* - ``sphinx.writers.html.HTMLTranslator._fieldlist_row_index``
- 4.3
- 6.0

View File

@@ -2329,12 +2329,11 @@ class SlotsMixin(DataDocumenterMixinBase):
return ret
def should_suppress_directive_header(self) -> bool:
def should_suppress_value_header(self) -> bool:
if self.object is SLOTSATTR:
self._datadescriptor = True
return True
else:
return super().should_suppress_directive_header()
return super().should_suppress_value_header()
def get_doc(self, ignore: int = None) -> Optional[List[List[str]]]:
if self.object is SLOTSATTR:
@@ -2352,6 +2351,15 @@ class SlotsMixin(DataDocumenterMixinBase):
else:
return super().get_doc(ignore) # type: ignore
@property
def _datadescriptor(self) -> bool:
warnings.warn('AttributeDocumenter._datadescriptor() is deprecated.',
RemovedInSphinx60Warning)
if self.object is SLOTSATTR:
return True
else:
return False
class RuntimeInstanceAttributeMixin(DataDocumenterMixinBase):
"""

View File

@@ -10,6 +10,7 @@ class Bar:
__slots__ = {'attr1': 'docstring of attr1',
'attr2': 'docstring of attr2',
'attr3': None}
__annotations__ = {'attr1': int}
def __init__(self):
self.attr2 = None #: docstring of instance attr2

View File

@@ -1359,6 +1359,7 @@ def test_slots(app):
'',
' .. py:attribute:: Bar.attr1',
' :module: target.slots',
' :type: int',
'',
' docstring of attr1',
'',

View File

@@ -129,6 +129,7 @@ def test_autoattribute_slots_variable_dict(app):
'',
'.. py:attribute:: Bar.attr1',
' :module: target.slots',
' :type: int',
'',
' docstring of attr1',
'',

View File

@@ -243,6 +243,7 @@ def test_slots_attribute(app):
'',
' .. py:attribute:: Bar.attr1',
' :module: target.slots',
' :type: int',
'',
' docstring of attr1',
'',