Skip to content

Commit b778ee8

Browse files
committed
Fix sphinx-doc#9752: autodoc: Failed to detect type annotation for slots attribute
1 parent e6f9603 commit b778ee8

File tree

7 files changed

+22
-3
lines changed

7 files changed

+22
-3
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Incompatible changes
2828
Deprecated
2929
----------
3030

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

doc/extdev/deprecated.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ The following is a list of deprecated interfaces.
2222
- (will be) Removed
2323
- Alternatives
2424

25+
* - ``sphinx.ext.autodoc.AttributeDocumenter._datadescriptor``
26+
- 4.3
27+
- 6.0
28+
- N/A
29+
2530
* - ``sphinx.writers.html.HTMLTranslator._fieldlist_row_index``
2631
- 4.3
2732
- 6.0

sphinx/ext/autodoc/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2329,12 +2329,11 @@ def import_object(self, raiseerror: bool = False) -> bool:
23292329

23302330
return ret
23312331

2332-
def should_suppress_directive_header(self) -> bool:
2332+
def should_suppress_value_header(self) -> bool:
23332333
if self.object is SLOTSATTR:
2334-
self._datadescriptor = True
23352334
return True
23362335
else:
2337-
return super().should_suppress_directive_header()
2336+
return super().should_suppress_value_header()
23382337

23392338
def get_doc(self, ignore: int = None) -> Optional[List[List[str]]]:
23402339
if self.object is SLOTSATTR:
@@ -2352,6 +2351,15 @@ def get_doc(self, ignore: int = None) -> Optional[List[List[str]]]:
23522351
else:
23532352
return super().get_doc(ignore) # type: ignore
23542353

2354+
@property
2355+
def _datadescriptor(self) -> bool:
2356+
warnings.warn('AttributeDocumenter._datadescriptor() is deprecated.',
2357+
RemovedInSphinx60Warning)
2358+
if self.object is SLOTSATTR:
2359+
return True
2360+
else:
2361+
return False
2362+
23552363

23562364
class RuntimeInstanceAttributeMixin(DataDocumenterMixinBase):
23572365
"""

tests/roots/test-ext-autodoc/target/slots.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Bar:
1010
__slots__ = {'attr1': 'docstring of attr1',
1111
'attr2': 'docstring of attr2',
1212
'attr3': None}
13+
__annotations__ = {'attr1': int}
1314

1415
def __init__(self):
1516
self.attr2 = None #: docstring of instance attr2

tests/test_ext_autodoc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,7 @@ def test_slots(app):
13591359
'',
13601360
' .. py:attribute:: Bar.attr1',
13611361
' :module: target.slots',
1362+
' :type: int',
13621363
'',
13631364
' docstring of attr1',
13641365
'',

tests/test_ext_autodoc_autoattribute.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ def test_autoattribute_slots_variable_dict(app):
129129
'',
130130
'.. py:attribute:: Bar.attr1',
131131
' :module: target.slots',
132+
' :type: int',
132133
'',
133134
' docstring of attr1',
134135
'',

tests/test_ext_autodoc_autoclass.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ def test_slots_attribute(app):
243243
'',
244244
' .. py:attribute:: Bar.attr1',
245245
' :module: target.slots',
246+
' :type: int',
246247
'',
247248
' docstring of attr1',
248249
'',

0 commit comments

Comments
 (0)