Lint against cases where user likely intended to use constrained type variables
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- mypy 1.18.2
- Python 3.14.0
- Windows 11
Instantiating the object of the class with the wrong syntax setting constraint types to the 2nd and 3rd arguments gets error properly as shown below:
# ↓↓↓↓↓↓↓↓↓↓ Wrong syntax
class MyCls[T: int, float, str]:
num: T
def __init__(self, x: T) -> None:
self.num = x
# Instantiation
MyCls[int](100)
# Error
error: Type application has too few types
But only defining the class with the wrong syntax doesn't get the error as shown below so the error should occur:
# ↓↓↓↓↓↓↓↓↓↓ Wrong syntax
class MyCls[T: int, float, str]:
num: T
def __init__(self, x: T) -> None:
self.num = x
# No error
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 minimal Python 3.14 example with mypy 1.18.2 and compare diagnostics for the declaration alone versus the type application. Trace the generic type-variable and constrained-type analysis entry point, then add coverage so the standalone declaration reports the intended diagnostic without regressing valid syntax.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100