[Python-checkins] (no subject)
Stéphane Wirtel
webhook-mailer at python.org
Fri Sep 13 12:40:59 EDT 2019
To: python-checkins at python.org
Subject: bpo-38122: minor fixes to AsyncMock spec handling (GH-16099)
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
https://github.com/python/cpython/commit/14fd925a18fe3db0922a7d798e373102fe7a=
8a9c
commit: 14fd925a18fe3db0922a7d798e373102fe7a8a9c
branch: master
author: Michael Foord <voidspace at users.noreply.github.com>
committer: St=C3=A9phane Wirtel <stephane at wirtel.be>
date: 2019年09月13日T17:40:56+01:00
summary:
bpo-38122: minor fixes to AsyncMock spec handling (GH-16099)
files:
M Lib/unittest/mock.py
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index 513cd5c924d4..b33d58a2cb0d 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -402,18 +402,12 @@ def __new__(cls, /, *args, **kw):
# so we can create magic methods on the
# class without stomping on other mocks
bases =3D (cls,)
- if not issubclass(cls, AsyncMock):
+ if not issubclass(cls, AsyncMockMixin):
# Check if spec is an async object or function
- sig =3D inspect.signature(NonCallableMock.__init__)
- bound_args =3D sig.bind_partial(cls, *args, **kw).arguments
- spec_arg =3D [
- arg for arg in bound_args.keys()
- if arg.startswith('spec')
- ]
- if spec_arg:
- # what if spec_set is different than spec?
- if _is_async_obj(bound_args[spec_arg[0]]):
- bases =3D (AsyncMockMixin, cls,)
+ bound_args =3D _MOCK_SIG.bind_partial(cls, *args, **kw).arguments
+ spec_arg =3D bound_args.get('spec_set', bound_args.get('spec'))
+ if spec_arg and _is_async_obj(spec_arg):
+ bases =3D (AsyncMockMixin, cls)
new =3D type(cls.__name__, bases, {'__doc__': cls.__doc__})
instance =3D object.__new__(new)
return instance
@@ -1020,6 +1014,9 @@ def _calls_repr(self, prefix=3D"Calls"):
return f"\n{prefix}: {safe_repr(self.mock_calls)}."
=20
=20
+_MOCK_SIG =3D inspect.signature(NonCallableMock.__init__)
+
+
class _AnyComparer(list):
"""A list which checks if it contains a call which may have an
argument of ANY, flipping the components of item and self from
More information about the Python-checkins
mailing list