mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #8338 from mgeier/autodoc-slots-str
autodoc: check whether __slots__ is a str
This commit is contained in:
commit
9188cba1c0
@ -206,7 +206,10 @@ def get_object_members(subject: Any, objpath: List[str], attrgetter: Callable,
|
|||||||
if isclass(subject) and getattr(subject, '__slots__', None) is not None:
|
if isclass(subject) and getattr(subject, '__slots__', None) is not None:
|
||||||
from sphinx.ext.autodoc import SLOTSATTR
|
from sphinx.ext.autodoc import SLOTSATTR
|
||||||
|
|
||||||
for name in subject.__slots__:
|
slots = subject.__slots__
|
||||||
|
if isinstance(slots, str):
|
||||||
|
slots = [slots]
|
||||||
|
for name in slots:
|
||||||
members[name] = Attribute(name, True, SLOTSATTR)
|
members[name] = Attribute(name, True, SLOTSATTR)
|
||||||
|
|
||||||
# other members
|
# other members
|
||||||
|
@ -2,6 +2,10 @@ class Foo:
|
|||||||
__slots__ = ['attr']
|
__slots__ = ['attr']
|
||||||
|
|
||||||
|
|
||||||
|
class FooSingleString:
|
||||||
|
__slots__ = 'attr'
|
||||||
|
|
||||||
|
|
||||||
class Bar:
|
class Bar:
|
||||||
__slots__ = {'attr1': 'docstring of attr1',
|
__slots__ = {'attr1': 'docstring of attr1',
|
||||||
'attr2': 'docstring of attr2',
|
'attr2': 'docstring of attr2',
|
||||||
|
@ -1205,6 +1205,14 @@ def test_slots(app):
|
|||||||
' .. py:attribute:: Foo.attr',
|
' .. py:attribute:: Foo.attr',
|
||||||
' :module: target.slots',
|
' :module: target.slots',
|
||||||
'',
|
'',
|
||||||
|
'',
|
||||||
|
'.. py:class:: FooSingleString()',
|
||||||
|
' :module: target.slots',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
' .. py:attribute:: FooSingleString.attr',
|
||||||
|
' :module: target.slots',
|
||||||
|
'',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user