◐ Shell
clean mode source ↗

Message 334398 - Python tracker

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')}