Merge pull request #8656 from tk0miya/8655_exception_on_hasattr

Fix #8655: autodoc: Crashes when object raises an exception on hasattr()
This commit is contained in:
Takeshi KOMIYA 2021-01-07 02:12:27 +09:00 committed by GitHub
commit ac12d8dabe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -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
--------

View File

@ -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