Closed as not planned
Description
Bug Report
Looks like mypy fail to consider that the following code is valid where pyright deals correctly with it. I think it is a false positive.
To Reproduce
from typing import get_args, Literal, Iterable
_Names = Literal["Joe", "Bob"]
_AllNames = Literal["Brian", _Names]
all_names: Iterable[_AllNames] = []
names: Iterable[_Names] = get_args(_Names)
filtered_names: Iterable[_Names] = [name for name in all_names if name in names] # fail here
Expected Behavior
I don't think it should throw an error since name
is a _Names
. Pyright is seeing this as correct code.
Actual Behavior
It is failing with the following error when copying the code in a file and running poetry run mypy ./test_literal.py --show-error-codes
test_literal.py:8: error: List comprehension has incompatible type List[Literal['Brian', 'Joe', 'Bob']]; expected List[Literal['Joe', 'Bob']] [misc]
test_literal.py:8: error: Unsupported operand types for in ("Literal['Brian', 'Joe', 'Bob']" and "Iterable[Literal['Joe', 'Bob']]") [operator]
Your Environment
- Mypy version used:
0.941
and0.961
- Python version used:
3.9.10
- Operating system and version:
Ubuntu 22.04 LTS