Skip to content

Error when inspecting the signature of AsyncMock() #504

Closed
@peter-slovak

Description

@peter-slovak

What versions are you using?

  • Python: 3.10.0
  • Mock: 5.0.0
  • Operating System: Linux

What happened?
Upgrading from mock==4.0.3 to mock==5.0.0 introduced an error while inspecting the signature of an AsyncMock() coroutine function. I noticed some AsyncMock()-related changes in the changelog, so I'm not sure whether this is the desired behavior, but AsyncMock() docs state that this should return a coroutine-function-like object which should be inspectable.

mock==4.0.3:

Python 3.10.0 (default, Nov  7 2022, 15:29:24) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import inspect, unittest.mock, mock
>>> f = unittest.mock.AsyncMock()
>>> inspect.signature(f)
<Signature (*args, **kwargs)>
>>> f = mock.AsyncMock()
>>> inspect.signature(f)
<Signature (*args, **kwargs)>

mock==5.0.0:

Python 3.10.0 (default, Nov  7 2022, 15:29:24) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import inspect, unittest.mock, mock
>>> f = unittest.mock.AsyncMock()
>>> inspect.signature(f)
<Signature (*args, **kwargs)>
>>> f = mock.AsyncMock()
>>> inspect.signature(f)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/.../.pyenv/versions/3.10.0/lib/python3.10/inspect.py", line 3245, in signature
    return Signature.from_callable(obj, follow_wrapped=follow_wrapped,
  File "/home/.../.pyenv/versions/3.10.0/lib/python3.10/inspect.py", line 2993, in from_callable
    return _signature_from_callable(obj, sigcls=cls,
  File "/home/.../.pyenv/versions/3.10.0/lib/python3.10/inspect.py", line 2454, in _signature_from_callable
    return _signature_from_function(sigcls, obj,
  File "/home/.../.pyenv/versions/3.10.0/lib/python3.10/inspect.py", line 2298, in _signature_from_function
    positional = arg_names[:pos_count]
TypeError: 'Mock' object is not subscriptable

Thank you for your time :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions