Skip to content

Commit

Permalink
gh-96127: Fix inspect.signature call on mocks (#96335)
Browse files Browse the repository at this point in the history
Backports: 9e7d7266ecdcccc02385fe4ccb094f3444102e26
Signed-off-by: Chris Withers <[email protected]>
  • Loading branch information
sobolevn authored and cjw296 committed Jan 9, 2023
1 parent 5219601 commit ee9744d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.d/2022-08-27-10-35-50.gh-issue-96127.8RdLre.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
``inspect.signature`` was raising ``TypeError`` on call with mock objects.
Now it correctly returns ``(*args, **kwargs)`` as infered signature.
10 changes: 9 additions & 1 deletion mock/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2258,7 +2258,15 @@ def __init__(self, *args, **kwargs):
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()
Expand Down

0 comments on commit ee9744d

Please sign in to comment.