inspect.signature with PEP 563
The point of using PEP 536 is to not evaluate the annotations unless needed. The signature merely reports on the annotations.
If for your purposes you need to have the annotations resolved, you have to do so yourself. PEP 536 tells documents how you do this:
For code that uses type hints, the
typing.get_type_hints(obj, globalns=None, localns=None)
function correctly evaluates expressions back from its string form.[...]
For code which uses annotations for other purposes, a regular eval(ann, globals, locals) call is enough to resolve the annotation.
You could even use the typing.get_type_hints()
function to assign back to __annotations__
before getting the signature:
import typing
Example.__new__.__annotations__ = typing.get_type_hints(Example.__new__)
signature: inspect.Signature = inspect.signature(Example)
Doing this is safe even if from __future__ import annotations
had not been used.