@@ -402,18 +402,12 @@ def __new__(cls, /, *args, **kw):
402
402
# so we can create magic methods on the
403
403
# class without stomping on other mocks
404
404
bases = (cls ,)
405
- if not issubclass (cls , AsyncMock ):
405
+ if not issubclass (cls , AsyncMockMixin ):
406
406
# Check if spec is an async object or function
407
- sig = inspect .signature (NonCallableMock .__init__ )
408
- bound_args = sig .bind_partial (cls , * args , ** kw ).arguments
409
- spec_arg = [
410
- arg for arg in bound_args .keys ()
411
- if arg .startswith ('spec' )
412
- ]
413
- if spec_arg :
414
- # what if spec_set is different than spec?
415
- if _is_async_obj (bound_args [spec_arg [0 ]]):
416
- bases = (AsyncMockMixin , cls ,)
407
+ bound_args = _MOCK_SIG .bind_partial (cls , * args , ** kw ).arguments
408
+ spec_arg = bound_args .get ('spec_set' , bound_args .get ('spec' ))
409
+ if spec_arg and _is_async_obj (spec_arg ):
410
+ bases = (AsyncMockMixin , cls )
417
411
new = type (cls .__name__ , bases , {'__doc__' : cls .__doc__ })
418
412
instance = object .__new__ (new )
419
413
return instance
@@ -1020,6 +1014,9 @@ def _calls_repr(self, prefix="Calls"):
1020
1014
return f"\n { prefix } : { safe_repr (self .mock_calls )} ."
1021
1015
1022
1016
1017
+ _MOCK_SIG = inspect .signature (NonCallableMock .__init__ )
1018
+
1019
+
1023
1020
class _AnyComparer (list ):
1024
1021
"""A list which checks if it contains a call which may have an
1025
1022
argument of ANY, flipping the components of item and self from
0 commit comments