For code that uses annotations / signature, wrapping a callable in a Mock object does not work correctly:
>>> import typing, inspect, functools
>>> from unittest.mock import Mock
>>>
>>> def incr(i: int) -> int:
... return i+1
...
>>> wrapped = Mock(wraps=incr)
>>> inspect.signature(wrapped)
<Signature (*args, **kwargs)>
>>> typing.get_type_hints(wrapped)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.11/typing.py", line 2330, in get_type_hints
raise TypeError('{!r} is not a module, class, method, '
TypeError: <Mock id='140078552596944'> is not a module, class, method, or function.
>>> functools.update_wrapper(wrapped, incr)
<Mock id='140078552596944'>
>>> inspect.signature(wrapped)
<Signature (i: int) -> int>
>>> typing.get_type_hints(wrapped)
{'i': <class 'int'>, 'return': <class 'int'>}
Does anyone see any problems with implementing this?
Thanks & best wishes,
Lucas Wiman