Non overlapping inclusion check for literal types
Open
Nobody has claimed this yet.
feature
topic-literal-types
topic-overlap
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Right now mypy spots an error on the first if condition but it would be great if it could also complain on the second one which seems a better expression of the first test:
from typing import Literal
literal_t = Literal['a', 'b', 'c']
x: literal_t = 'b'
if x == 'a' or x == 'd': ...
if x in ('a', 'd'): ...
mypy version:
$ mypy --version
mypy 0.920+dev.bbea3b56297d3d966b9a98900c218df6616fec85
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
Reproduce the issue with the provided Python snippet and mypy version, then locate the existing diagnostic for the equality checks and the handling of in expressions. Done means mypy reports the equivalent non-overlapping literal-type condition for the tuple-membership form without regressing the existing check.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100