Open
Description
a: list[int | None] = [1] + [2] + [None]
b: list[int | None] = [1] + [2]
c: list[int | None] = [1, 2]
a is okay, b is an error, c is okay
Apologies if this is a repeat / common issue. I couldn't find anything in the docs. This is popping up for me a lot, my interpretation is that mypy allows type invariance on literals that it will not for expressions.
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.11&gist=b999a1bd2e975645b868c0b376c910e8
Expected Behavior
Either b
and c
should both be errors or (preferably) neither.
Actual Behavior
b
is an error but c
isn't
Your Environment
- Mypy version used: 1.7.1 and master
- Python version used: 3.11
Metadata
Metadata
Assignees
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
glenrobertson commentedon Dec 5, 2023
+1 also experiencing this issue! any help would be greatly appreciated.