Код: Выделить всё
# NOTE:
# This code does not work!
#
# If I define `ret_type = TypeVar("ret_type")` it becomes syntactically
# correct, but type hinting is still broken.
#
def mycoerce(data: Any, ret_type: type) -> ret_type
return ret_type(data)
a = mycoerce("123", int) # desired: a type hinted to int
b = mycoerce("123", float) # desired: b type hinted to float
Подробнее здесь: https://stackoverflow.com/questions/703 ... -parameter