Skip to content

Commit

Permalink
Merge pull request #8656 from tk0miya/8655_exception_on_hasattr
Browse files Browse the repository at this point in the history
Fix #8655: autodoc: Crashes when object raises an exception on hasattr()
  • Loading branch information
tk0miya authored Jan 6, 2021
2 parents 4755557 + a51c8a5 commit ac12d8d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------

Expand Down
5 changes: 4 additions & 1 deletion sphinx/ext/autodoc/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ac12d8d

Please sign in to comment.