python / python/typeshed

Strict equality not working between string and uuid

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

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

主要言語
Python
スター
5.1k
フォーク
2.1k
平均マージ
1日 19時間
マージ済み PR(30日)
82

説明

Bug Report

--strict-equality seems to only work in very reduced cases. In particular, it is not working when comparing strings and uuids.

To Reproduce

import uuid
from typing import TYPE_CHECKING, reveal_type

a = uuid.uuid4()
b = str(a)

if TYPE_CHECKING:
  reveal_type(a)
  reveal_type(b)
print(a == b)

c = "c"
d = 500
print(c == d)

https://mypy-play.net/?mypy=latest&python=3.12&flags=show-error-codes%2Cstrict-equality&gist=6c8273316b52930967ad0f8062c57aa3

Expected Behavior

The comparison in line 10 should raise a comparison overlap error. Something like

test_strict_equality.py:10: error: Non-overlapping equality check (left operand type: "str", right operand type: "uuid.UUID")  [comparison-overlap]

Actual Behavior

Mypy does not flag the string/UUID comparison as incompatible

test_strict_equality.py:8: note: Revealed type is "uuid.UUID"
test_strict_equality.py:9: note: Revealed type is "builtins.str"
test_strict_equality.py:14: error: Non-overlapping equality check (left operand type: "str", right operand type: "int")  [comparison-overlap]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.15.0
  • Mypy command-line flags: --strict-equality --show-error-codes
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.12.9

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

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

はじめの一歩

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

調査の方向性

まず、提供されている Python reproducer を mypy 1.15.0、Python 3.12.9、--strict-equality、--show-error-codes で実行します。string/uuid.UUID の等価比較が報告されず、string/int は報告される理由を調査し、その後このケースの coverage を追加または更新します。UUID の比較で comparison-overlap エラーが発生し、既存の string/int の動作を変更しなければ完了です。

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

評価

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

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

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