[issue35834] get_type_hints exposes an instance of ForwardRef (internal class) in its result, with `from __future__ import annotations` enabled
Steven D'Aprano
report at bugs.python.org
Sat Jan 26 12:44:17 EST 2019
Steven D'Aprano <steve+python at pearwood.info> added the comment:
Wait, I just noticed that PEP563 says:
"Note: if an annotation was a string literal already, it will still be wrapped in a string."
https://www.python.org/dev/peps/pep-0563/#id5
In 3.8.0a I get this:
py> from __future__ import annotations
py>
py> class A:
... f: 'Undef'
...
py> A.__annotations__
{'f': "'Undef'"}
which matches what the PEP says. So I expect that when calling get_type_hints it should return the unquoted string, rather than a ForwardReference.
get_type_hints(A)
expected {'f': 'Undef'}
actually got {'f': ForwardRef('Undef')}
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35834>
_______________________________________
More information about the Python-bugs-list
mailing list