mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #8462 from tk0miya/handle_AttributeError_from_getall
Handle AttributeError from getall() and getslots()
This commit is contained in:
@@ -991,6 +991,10 @@ class ModuleDocumenter(Documenter):
|
||||
try:
|
||||
if not self.options.ignore_module_all:
|
||||
self.__all__ = inspect.getall(self.object)
|
||||
except AttributeError as exc:
|
||||
# __all__ raises an error.
|
||||
logger.warning(__('%s.__all__ raises an error. Ignored: %r'),
|
||||
(self.fullname, exc), type='autodoc')
|
||||
except ValueError as exc:
|
||||
# invalid __all__ found.
|
||||
logger.warning(__('__all__ should be a list of strings, not %r '
|
||||
@@ -2270,11 +2274,17 @@ class SlotsAttributeDocumenter(AttributeDocumenter):
|
||||
% self.__class__.__name__,
|
||||
RemovedInSphinx50Warning, stacklevel=2)
|
||||
name = self.objpath[-1]
|
||||
__slots__ = inspect.getslots(self.parent)
|
||||
if __slots__ and isinstance(__slots__.get(name, None), str):
|
||||
docstring = prepare_docstring(__slots__[name])
|
||||
return [docstring]
|
||||
else:
|
||||
|
||||
try:
|
||||
__slots__ = inspect.getslots(self.parent)
|
||||
if __slots__ and isinstance(__slots__.get(name, None), str):
|
||||
docstring = prepare_docstring(__slots__[name])
|
||||
return [docstring]
|
||||
else:
|
||||
return []
|
||||
except (AttributeError, ValueError) as exc:
|
||||
logger.warning(__('Invalid __slots__ found on %s. Ignored.'),
|
||||
(self.parent.__qualname__, exc), type='autodoc')
|
||||
return []
|
||||
|
||||
|
||||
|
||||
@@ -210,7 +210,7 @@ def get_object_members(subject: Any, objpath: List[str], attrgetter: Callable,
|
||||
|
||||
for name in __slots__:
|
||||
members[name] = Attribute(name, True, SLOTSATTR)
|
||||
except (TypeError, ValueError):
|
||||
except (AttributeError, TypeError, ValueError):
|
||||
pass
|
||||
|
||||
# other members
|
||||
|
||||
@@ -141,6 +141,7 @@ def getall(obj: Any) -> Optional[Sequence[str]]:
|
||||
"""Get __all__ attribute of the module as dict.
|
||||
|
||||
Return None if given *obj* does not have __all__.
|
||||
Raises AttributeError if given *obj* raises an error on accessing __all__.
|
||||
Raises ValueError if given *obj* have invalid __all__.
|
||||
"""
|
||||
__all__ = safe_getattr(obj, '__all__', None)
|
||||
@@ -157,6 +158,8 @@ def getslots(obj: Any) -> Optional[Dict]:
|
||||
"""Get __slots__ attribute of the class as dict.
|
||||
|
||||
Return None if gienv *obj* does not have __slots__.
|
||||
Raises AttributeError if given *obj* raises an error on accessing __slots__.
|
||||
Raises ValueError if given *obj* have invalid __slots__.
|
||||
"""
|
||||
if not inspect.isclass(obj):
|
||||
raise TypeError
|
||||
|
||||
Reference in New Issue
Block a user