python / python/mypy

mypy throws `assignment` error for a list created from an empty list

Offen
#18,735 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

feature topic-type-variables topic-union-types
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

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Ö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

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.