Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -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``
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions doc/extdev/deprecated.rst
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions sphinx/ext/autodoc/__init__.py
Expand Up @@ -2329,12 +2329,11 @@ def import_object(self, raiseerror: bool = False) -> bool:

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:
Expand All @@ -2352,6 +2351,15 @@ def get_doc(self, ignore: int = None) -> Optional[List[List[str]]]:
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):
"""
Expand Down
1 change: 1 addition & 0 deletions tests/roots/test-ext-autodoc/target/slots.py
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/test_ext_autodoc.py
Expand Up @@ -1359,6 +1359,7 @@ def test_slots(app):
'',
' .. py:attribute:: Bar.attr1',
' :module: target.slots',
' :type: int',
'',
' docstring of attr1',
'',
Expand Down
1 change: 1 addition & 0 deletions tests/test_ext_autodoc_autoattribute.py
Expand Up @@ -129,6 +129,7 @@ def test_autoattribute_slots_variable_dict(app):
'',
'.. py:attribute:: Bar.attr1',
' :module: target.slots',
' :type: int',
'',
' docstring of attr1',
'',
Expand Down
1 change: 1 addition & 0 deletions tests/test_ext_autodoc_autoclass.py
Expand Up @@ -243,6 +243,7 @@ def test_slots_attribute(app):
'',
' .. py:attribute:: Bar.attr1',
' :module: target.slots',
' :type: int',
'',
' docstring of attr1',
'',
Expand Down