python / python/mypy

Direction of comparison operator in error message does not depend on direction in code

Offen
#17,460 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug priority-2-low
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Bug Report

When encountering an error due to using a comparison operator with None as one of the arguments, Mypy adjusts the direction of < and > operators in its messages based on the types involved so that it always reports None as the second type (e.g. Unsupported operand types for {comparisson operator direction} ("int" and "None")). This becomes increasingly confusing when both variables in the comparison could potentially be a large number of types.

To reproduce

For the following code

1 < None
1 > None
None < 1
None > 1

Expected Behavior

file.py:1: error: Unsupported operand types for < ("int" and "None")  [operator]
file.py:2: error: Unsupported operand types for > ("int" and "None")  [operator]
file.py:3: error: Unsupported operand types for < ("None" and "int")  [operator]
file.py:4: error: Unsupported operand types for > ("None" and "int")  [operator]

Actual Behavior

file.py:1: error: Unsupported operand types for < ("int" and "None")  [operator]
file.py:2: error: Unsupported operand types for > ("int" and "None")  [operator]
file.py:3: error: Unsupported operand types for > ("int" and "None")  [operator]
file.py:4: error: Unsupported operand types for < ("int" and "None")  [operator]

Your Environment

  • Mypy version used: 1.10
  • Python version used: 3.12

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

Beginne damit, die vier Vergleichsfälle aus dem Issue mit mypy 1.10 zu reproduzieren, und verfolge dann den Diagnosepfad, der nicht unterstützte Operandentypen formatiert. Füge Regressionsabdeckung für beide Operandenreihenfolgen hinzu und überprüfe, dass jede Meldung den Quelloperator und die in der erwarteten Ausgabe gezeigte Operandenreihenfolge beibehält.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
devtools
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
48/100

Neue Issues direkt in Ihr Postfach

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