diff --git a/CHANGES b/CHANGES index 7139f6540fb..24ebde5aad4 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,9 @@ Features added Bugs fixed ---------- +* #8655: autodoc: Failed to generate document if target module contains an + object that raises an exception on ``hasattr()`` + Testing -------- diff --git a/sphinx/ext/autodoc/mock.py b/sphinx/ext/autodoc/mock.py index 381848fc120..3d4f7641039 100644 --- a/sphinx/ext/autodoc/mock.py +++ b/sphinx/ext/autodoc/mock.py @@ -153,7 +153,10 @@ def mock(modnames: List[str]) -> Generator[None, None, None]: def ismock(subject: Any) -> bool: """Check if the object is mocked.""" # 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 # check the object is mocked module