from __future__ import annotations def foo() -> int | str: pass eval(foo.__annotations__['return'])