`UNBOUND_TYPEVAR` error message should be more direct and shorter
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
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 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the mypy test.py examples and locate where the UNBOUND_TYPEVAR diagnostic is generated and tested. Update the message to the shorter wording requested, then verify that the three failing examples produce the new diagnostic without changing the valid example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100