[New-bugs-announce] [issue41872] get_type_hints fails to resolve forward references in nested function
Chris Withers
report at bugs.python.org
Sun Sep 27 09:58:04 EDT 2020
New submission from Chris Withers <chris at withers.org>:
Reproducer:
def test_forward_type_references(self):
def foo(a: 'Foo') -> 'Bar': pass
class Foo: pass
class Bar: pass
get_type_hints(foo)
The above gives the following exception, rather than resolving the type:
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/typing.py:1001: in get_type_hints
value = _eval_type(value, globalns, localns)
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/typing.py:260: in _eval_type
return t._evaluate(globalns, localns)
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/typing.py:464: in _evaluate
eval(self.__forward_code__, globalns, localns),
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> ???
E NameError: name 'Foo' is not defined
----------
components: Library (Lib)
messages: 377569
nosy: cjw296
priority: normal
severity: normal
status: open
title: get_type_hints fails to resolve forward references in nested function
type: behavior
versions: Python 3.10, Python 3.7, Python 3.8, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41872>
_______________________________________
More information about the New-bugs-announce
mailing list