*Notes:
The last 3 examples get the same indirect and long error messages of UNBOUND_TYPEVAR as shown below:
*Notes:
- A parameter is a variable defined in a function header to receive an argument.
- An argument is a value passed to a function parameter.
A function returning TypeVar should receive at least one argument containing the same TypeVar
With T for x:
def func[T](x: T) -> T:
return x
# No error
Without T for x:
def func[T](x) -> T:
return x
# error: A function returning TypeVar should receive at least one argument containing the same TypeVar
With no parameters:
from typing import cast
def func[T]() -> T:
return cast(T, 'Hello')
# error: A function returning TypeVar should receive at least one argument containing the same TypeVar
With T1 for x and T2 for return type:
def func[T1, T2](x: T1) -> T2:
return x
# error: A function returning TypeVar should receive at least one argument containing the same TypeVar
So, the same indirect and long error messages of UNBOUND_TYPEVAR should be changed:
From:
A function returning TypeVar should receive at least one argument containing the same TypeVar
To more direct and shorter one below:
A function returning TypeVar should have at least one same TypeVar parameter
*Notes:
The last 3 examples get the same indirect and long error messages of
UNBOUND_TYPEVARas shown below:*Notes:
With
Tforx:Without
Tforx:With no parameters:
With
T1forxandT2for return type:So, the same indirect and long error messages of
UNBOUND_TYPEVARshould be changed:From:
To more direct and shorter one below: