[issue43463] typing.get_type_hints with TYPE_CHECKING imports / getting hints for single argument

Ken Jin report at bugs.python.org
Mon Mar 15 13:28:53 EDT 2021


Ken Jin <kenjin4096 at gmail.com> added the comment:

@Florian,

IIUC inspect.signature auto-resolves string annotations to typing.ForwardRef internally from 3.10 onwards. It's mentioned in the what's new for PEP 563 https://docs.python.org/3.10/whatsnew/3.10.html#pep-563-postponed-evaluation-of-annotations-becomes-default

If it fails, it will just give the string. So the only place where inspect.signature might start giving you different output is if you previously defined a function like so:

def foo(a: 'MyType'): ...

And you expected inspect.signature.paramters to be ``[<Parameter "a: 'MyType'">]`` (the string). However if MyType is in globals()/locals(), you'll instead get ``[<Parameter "a: MyType">]`` in 3.10.

FWIW someone already reported that in Issue43355.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43463>
_______________________________________


More information about the Python-bugs-list mailing list