mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #8655: autodoc: Crashes when object raises an exception on hasattr()
autodoc crashes when the target object raises an exception on `hasattr()`. The `hasattr()` function internally calls the `obj.__getattr__()` or `obj.__getattribute__()` of the target object. Hence the reaction can be changed on the target object. This starts to use `safe_getattr()` to check the object is mocked or not and to prevent an unexpected error.
This commit is contained in:
3
CHANGES
3
CHANGES
@@ -16,6 +16,9 @@ Features added
|
|||||||
Bugs fixed
|
Bugs fixed
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
* #8655: autodoc: Failed to generate document if target module contains an
|
||||||
|
object that raises an exception on ``hasattr()``
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
|||||||
@@ -153,7 +153,10 @@ def mock(modnames: List[str]) -> Generator[None, None, None]:
|
|||||||
def ismock(subject: Any) -> bool:
|
def ismock(subject: Any) -> bool:
|
||||||
"""Check if the object is mocked."""
|
"""Check if the object is mocked."""
|
||||||
# check the object has '__sphinx_mock__' attribute
|
# check the object has '__sphinx_mock__' attribute
|
||||||
if not hasattr(subject, '__sphinx_mock__'):
|
try:
|
||||||
|
if safe_getattr(subject, '__sphinx_mock__', None) is None:
|
||||||
|
return False
|
||||||
|
except AttributeError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# check the object is mocked module
|
# check the object is mocked module
|
||||||
|
|||||||
Reference in New Issue
Block a user