Literal infers tuple literal as Union of the items though this syntax is forbidden by PEP 586
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
The section Illegal parameters for Literal at type check time describes that tuple literals inside Literal are forbidden:
Tuples containing valid literal types like
Literal[(1, "foo", "bar")]. The user could always express this type asTuple[Literal[1], Literal["foo"], Literal["bar"]]instead. Also, tuples are likely to be confused with theLiteral[1, 2, 3]shortcut.
Nevertheless mypy seems to be taking this shortcut since it doesn't flag the following code:
from typing_extensions import Literal
a : Literal[(1, 2)] = 1
Python 3.7, mypy 0.740, typing-extensions 3.7.4.
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 reproducing the reported Python snippet using Literal[(1, 2)] and confirm whether mypy accepts it. Locate the Literal type-checking path and its existing tests; done means tuple literals in Literal are rejected in accordance with PEP 586.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100