-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugmypy got something wrongmypy got something wrong
Description
*Notes:
- mypy test.py
- mypy 1.19.1
- Python 3.14.0
- Related comment
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 errorWithout T for x:
def func[T](x) -> T:
return x
# error: A function returning TypeVar should receive at least one argument containing the same TypeVarWith 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 TypeVarWith 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 TypeVarSo, 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong