Containment checks for separate types raises error
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
If a containment check is done on non-overlapping types, mypy reports an error although the code is type safe.
Further information: https://github.com/python/typing/discussions/1464
To Reproduce
from enum import Enum
class Foo(str, Enum):
BAR = "bar"
contains = "foo" in iter(Foo)
# or, even more simple but unusual code:
contains = "foo" in iter([1])
Expected Behavior
The code is type safe. The first example actually checks the containment in the iterator, the second example will always return false, but is still valid code. Mypy should not report an error for either case.
Actual Behavior
test.py:6: error: Unsupported operand types for in ("str" and "Iterator[Foo]") [operator]
test.py:8: error: Unsupported operand types for in ("str" and "Iterator[int]") [operator]
Your Environment
- Mypy version used: 1.5.1
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.11.3
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Führe zunächst mypy für den Reproducer im Issue aus und verfolge den Pfad der Typprüfung für Containment/Operatoren. Füge einen Regressionstest für beide Iterator-Beispiele hinzu und überprüfe anschließend, dass mypy sie akzeptiert, ohne gültige Diagnosen zu inkompatiblen Typen abzuschwächen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100