From 4a977ba4e19ae00307f7d5496bc0703e8871888b Mon Sep 17 00:00:00 2001 From: Christian Walch Date: Thu, 31 Mar 2022 09:33:54 +0200 Subject: [PATCH] Use recursive call to `ismock()` on unbound method instead of using temporary object. --- sphinx/ext/autodoc/mock.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sphinx/ext/autodoc/mock.py b/sphinx/ext/autodoc/mock.py index e124ef3e0..5a87c3d8c 100644 --- a/sphinx/ext/autodoc/mock.py +++ b/sphinx/ext/autodoc/mock.py @@ -173,13 +173,11 @@ def ismock(subject: Any) -> bool: # check the object is bound method if isinstance(subject, MethodType) and _method_is_bound(subject): - tmp_subject = subject.__func__ - else: - tmp_subject = subject + return ismock(subject.__func__) try: # check the object is mocked object - __mro__ = safe_getattr(type(tmp_subject), '__mro__', []) + __mro__ = safe_getattr(type(subject), '__mro__', []) if len(__mro__) > 2 and __mro__[-2] is _MockObject: # A mocked object has a MRO that ends with (..., _MockObject, object). return True