Direction of comparison operator in error message does not depend on direction in code
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo i quattro casi di confronto dell’issue con mypy 1.10, quindi segui il percorso diagnostico che formatta i tipi di operandi non supportati. Aggiungi una copertura di regressione per entrambi gli ordini degli operandi e verifica che ogni messaggio mantenga l’operatore sorgente e l’ordine degli operandi mostrato nell’output previsto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 48/100