About `TypeVar`, passing a `name` keyword argument to `name` keyword and positional parameter gets error
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
*Memo:
- mypy test.py
- python test.py
- pyright test.py # Strict mode
- mypy 1.19.1
- Python 3.14.0
- Windows 11
The doc of TypeVar indicates name parameter is both a keyword and positional parameter as shown below:
class typing.TypeVar(name, *constraints, bound=None, covariant=False, contravariant=False, infer_variance=False, default=typing.NoDefault)
But with mypy, passing a name keyword argument to name keyword and positional parameter gets the error as shown below:
*Memo:
- No error occurs at runtime.
- pyright gives no error even with strict mode.
from typing import TypeVar
# ↓↓↓↓↓
T = TypeVar(name='T')
# Error
error: TypeVar() expects a string literal as first argument
So, mypy should accept a name keyword argument.
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 by running the reported mypy test.py example with mypy 1.19.1, then compare its result with Python runtime behavior and pyright in strict mode. Trace the TypeVar call handling and add a regression test for TypeVar(name='T'); done means mypy accepts the keyword form without regressing positional handling.
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
- Clearly specified
- Newbie friendliness
- 52/100