diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2023-12-24 11:38:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-24 11:38:56 (GMT) |
commit | 0c574540e07792cef5487aef61ab38bfe404060f (patch) | |
tree | 49807ad37ae47cc1972364c018108aa4927e9172 /Lib/unittest | |
parent | 0d74e9683b8567df933e415abf747d9e0b4cd7ef (diff) | |
download | cpython-0c574540e07792cef5487aef61ab38bfe404060f.zip cpython-0c574540e07792cef5487aef61ab38bfe404060f.tar.gz cpython-0c574540e07792cef5487aef61ab38bfe404060f.tar.bz2 |
gh-113407: Fix import of unittest.mock when CPython is built without docstrings (GH-113408)
Diffstat (limited to 'Lib/unittest')
-rw-r--r-- | Lib/unittest/mock.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index c6b46ee..2adb3d7 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -2229,8 +2229,11 @@ class MagicProxy(Base): return self.create_mock() -_CODE_ATTRS = dir(CodeType) -_CODE_SIG = inspect.signature(partial(CodeType.__init__, None)) +try: + _CODE_SIG = inspect.signature(partial(CodeType.__init__, None)) + _CODE_ATTRS = dir(CodeType) +except ValueError: + _CODE_SIG = None class AsyncMockMixin(Base): @@ -2250,9 +2253,12 @@ class AsyncMockMixin(Base): self.__dict__['_mock_await_count'] = 0 self.__dict__['_mock_await_args'] = None self.__dict__['_mock_await_args_list'] = _CallList() - code_mock = NonCallableMock(spec_set=_CODE_ATTRS) - code_mock.__dict__["_spec_class"] = CodeType - code_mock.__dict__["_spec_signature"] = _CODE_SIG + if _CODE_SIG: + code_mock = NonCallableMock(spec_set=_CODE_ATTRS) + code_mock.__dict__["_spec_class"] = CodeType + code_mock.__dict__["_spec_signature"] = _CODE_SIG + else: + code_mock = NonCallableMock(spec_set=CodeType) code_mock.co_flags = ( inspect.CO_COROUTINE + inspect.CO_VARARGS |