-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling inspect.signature with an AsyncMock instance raises an exception #96127
Comments
Related? #94924 |
This could be due to commit 4261b6b
|
@graingert yes, your link was very useful. Please, take a look at my proposed soultion :) |
@sobolevn - where is your proposed solution? |
|
Looks like this has been fixed, thanks all! |
I'm on 3.11.1 and this is happening. def _signature_from_function(cls, func, skip_bound_arg=True,
globals=None, locals=None, eval_str=False):
"""Private helper: constructs Signature for the given python function."""
is_duck_function = False
if not isfunction(func):
if _signature_is_functionlike(func):
is_duck_function = True
else:
# If it's not a pure Python function, and not a duck type
# of pure function:
raise TypeError('{!r} is not a Python function'.format(func))
s = getattr(func, "__text_signature__", None)
if s:
return _signature_fromstr(cls, func, s, skip_bound_arg)
Parameter = cls._parameter_cls
# Parameter information.
func_code = func.__code__
pos_count = func_code.co_argcount
arg_names = func_code.co_varnames
posonly_count = func_code.co_posonlyargcount
> positional = arg_names[:pos_count]
E TypeError: 'Mock' object is not subscriptable |
This commit is present on main branch and 3.12 latest alpha. I guess this is not backported. |
Workaround: from inspect import signature
from unittest.mock import AsyncMock, MagicMock
temp_mock = AsyncMock()
mock = MagicMock(return_value=temp_mock())
signature(mock) |
@sobolevn should the PR be backported to 3.11? |
Automatic backport has failed :( |
Got it, will start this in a couple of hours. |
(cherry picked from commit 9e7d726)
(cherry picked from commit 9e7d726)
@sobolevn ping? |
) (cherry picked from commit 9e7d726) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
@mdczaplicki @tirkarthi The backporting is done. The fix will be available in 3.11.3 |
Fixed by gh-96335. |
@arhadthedev where is the 3.10 backport? |
I confused it with my other issue that was backported to both versions. Thank you for pointing out, edited. |
GH-108652 is a backport of this pull request to the 3.10 branch. |
Bug report
Starting in Python 3.10.6, the following code raises an exception:
Mock
is used.Your environment
Linked PRs
inspect.signature
call on mocks #96335inspect.signature
call on mocks (#96335) #101646inspect.signature
call on mocks (#96335) #101647inspect.signature
call on mocks (#96335) (gh-96127) #108652The text was updated successfully, but these errors were encountered: