mypy throws `assignment` error for a list created from an empty list
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Bug Report
mypy fails to proceed sorting of the empty list, considering it's a list[object], see the reproduce script and the output
To Reproduce
a: list[str] | list[int] = []
a = sorted(a)
Expected Behavior
There shouldn't be errors
Actual Behavior
> mypy .
/tmp/test.py:2: error: Incompatible types in assignment (expression has type "list[SupportsDunderLT[Any] | SupportsDunderGT[Any]]", variable has type "list[str] | list[int]") [assignment]
Your Environment
- Mypy version used:
mypy 1.14.0 (compiled: no) - Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.13.2
In the scope of https://github.com/ClickHouse/ClickHouse/pull/76679
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
Verwende /tmp/test.py als Reproducer und führe mypy . mit mypy 1.14.0 und Python 3.13.2 aus. Untersuche die Zuweisungsdiagnose für sorted(a), wenn a list[str] | list[int] ist. Die Aufgabe ist abgeschlossen, wenn dieses Beispiel ohne Fehler die Typprüfung besteht und eine Regression-Prüfung es abdeckt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers, devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100