Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34.2k
Open
Description
Bug report
Bug description:
fromtypingimportTYPE_CHECKINGfromunittest.mockimportcreate_autospecifTYPE_CHECKING:fromfooimportFoodefbar(x:Foo)->None:passcreate_autospec(bar)
This will result inNameError: name 'Foo' is not defined because_get_signature_object inunittest.mock callsinspect.signature without explicitly passingannotation_format, so it defaults toFormat.VALUE.
Sincecreate_autospec really shouldn't care whether or not the annotations can be evaluated at runtime on the given object, I would suggest switching over toFormat.FORWARDREF orFormat.STRING, so autospeccing continues to work in Python 3.14+ for people that used to rely onfrom __future__ import annotations and now want to switch to PEP 649 semantics, without needing to change their code.
CPython versions tested on:
3.14
Operating systems tested on:
Linux