diff options
author | Nikita Sobolev <mail@sobolevn.me> | 2023-01-07 13:49:15 +0300 |
---|---|---|
committer | Chris Withers <chris@withers.org> | 2023-01-09 17:34:46 +0000 |
commit | ee9744d2d17e67e9f28d485e51df84d3154bc8b8 (patch) | |
tree | b1b08cd6d56867d13ae55c30ca523c5ec61a7aaf | |
parent | 521960196a665d6e53807277407cac9c9f933bdf (diff) | |
download | mock-ee9744d2d17e67e9f28d485e51df84d3154bc8b8.tar.gz |
gh-96127: Fix `inspect.signature` call on mocks (#96335)
Backports: 9e7d7266ecdcccc02385fe4ccb094f3444102e26
Signed-off-by: Chris Withers <chris@simplistix.co.uk>
-rw-r--r-- | NEWS.d/2022-08-27-10-35-50.gh-issue-96127.8RdLre.rst | 2 | ||||
-rw-r--r-- | mock/mock.py | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/NEWS.d/2022-08-27-10-35-50.gh-issue-96127.8RdLre.rst b/NEWS.d/2022-08-27-10-35-50.gh-issue-96127.8RdLre.rst new file mode 100644 index 0000000..79edd8f --- /dev/null +++ b/NEWS.d/2022-08-27-10-35-50.gh-issue-96127.8RdLre.rst @@ -0,0 +1,2 @@ +``inspect.signature`` was raising ``TypeError`` on call with mock objects. +Now it correctly returns ``(*args, **kwargs)`` as infered signature. diff --git a/mock/mock.py b/mock/mock.py index 6d76453..bf292b4 100644 --- a/mock/mock.py +++ b/mock/mock.py @@ -2258,7 +2258,15 @@ class AsyncMockMixin(Base): code_mock = NonCallableMock(spec_set=_CODE_ATTRS) code_mock.__dict__["_spec_class"] = CodeType code_mock.__dict__["_spec_signature"] = _CODE_SIG - code_mock.co_flags = inspect.CO_COROUTINE + code_mock.co_flags = ( + inspect.CO_COROUTINE + + inspect.CO_VARARGS + + inspect.CO_VARKEYWORDS + ) + code_mock.co_argcount = 0 + code_mock.co_varnames = ('args', 'kwargs') + code_mock.co_posonlyargcount = 0 + code_mock.co_kwonlyargcount = 0 self.__dict__['__code__'] = code_mock self.__dict__['__name__'] = 'AsyncMock' self.__dict__['__defaults__'] = tuple() |