Type annotation "List"[int] generates runtime error but is accepted by mypy
Open
Nobody has claimed this yet.
feature
priority-2-low
topic-quoted-annotations
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
This bug was just logged against pyright (and fixed): https://github.com/microsoft/pyright/issues/1393
I noticed that mypy also fails to report this error.
from typing import List
foo: "List"[int] = [1] # Accepted by mypy but generates runtime 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 with the supplied Python reproducer and compare mypy's result with the linked pyright issue. Trace how mypy handles a quoted "List" annotation followed by subscripting, then add a regression test demonstrating that the invalid annotation is reported rather than accepted. Done means the test passes and mypy no longer accepts this example silently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100