python / python/mypy

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

オープン
#17,460 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug priority-2-low
主要言語
Python
スター
20.6k
フォーク
3.3k
平均マージ
1日 18時間
マージ済み PR(30日)
54

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、mypy 1.10 で issue にある4つの比較ケースを再現し、次に、サポートされていないオペランド型をフォーマットする診断パスを追跡します。両方のオペランド順序についてリグレッションカバレッジを追加し、各メッセージが期待される出力に示されたソース演算子とオペランド順序を保持することを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
devtools
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
48/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。