Reduce complexity by removing recursion.

This commit is contained in:
Christian Walch 2022-04-01 07:45:53 +02:00
parent 57d6ec7697
commit 5a293346cf

View File

@ -166,11 +166,13 @@ def ismock(subject: Any) -> bool:
# check the object is bound method
if isinstance(subject, MethodType) and isboundmethod(subject):
return ismock(subject.__func__)
tmp_subject = subject.__func__
else:
tmp_subject = subject
try:
# check the object is mocked object
__mro__ = safe_getattr(type(subject), '__mro__', [])
__mro__ = safe_getattr(type(tmp_subject), '__mro__', [])
if len(__mro__) > 2 and __mro__[-2] is _MockObject:
# A mocked object has a MRO that ends with (..., _MockObject, object).
return True