from typing import get_type_hints def func(s: str) -> int: return int(s) hints = get_type_hints(func) # The order of type hints matters for certain functions # e.g. functools.singledispatch assert list(hints.items()) == [('s', str), ('return', int)]