As this great answer suggests, from Python 3.7 onward it's possible to use forward declarations in type annotations if the
from __future__ import annotations
instruction is used.
However, this still doesn't work if I want to create an alias for the annotation type:
from __future__ import annotations
import typing
MyType1 = typing.Union[str, MyType2]
MyType2 = typing.Mapping[str, MyType1]
This still gives me NameError: name 'MyType2' is not defined
I know about the fallback syntax using string literals, and it does work. However, I'm curious whether it's somehow possible to use the formally available new approach.