python / python/mypy

Mypy allows to compare NewTypes created from Decimal

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

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

bug
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

Bug Report

Mypy does not produce an error when comparing NewTypes based on Decimal.

To Reproduce

from decimal import Decimal
from typing import NewType

# Comparing Decimal NewTypes is OK 
FirstDecimal = NewType("FirstDecimal", Decimal)
SecondDecimal = NewType("SecondDecimal", Decimal)

FirstDecimal(Decimal("0.1")) == SecondDecimal(Decimal("0.1"))  # ! mypy ok

# But comparing other NewTypes is not
FirstInt = NewType("FirstInt", int)
SecondInt = NewType("SecondInt", int)

FirstInt(1) == SecondInt(3)  # mypy error

FirstString = NewType("FirstString", str)
SecondString = NewType("SecondString", str)

FirstString("bam") == SecondString("boo")  # mypy error

Expected Behavior

Mypy produces Non-overlapping equality check for all three comparisons.

Actual Behavior

Mypy produces Non-overlapping equality check only for int and str NewTypes.

Your Environment

  • Mypy version used: 1.1.1
  • Mypy command-line flags: --strict
  • Mypy configuration options from mypy.ini (and other config files):
[tool.mypy]
strict = true
show_error_context = true
show_error_codes = true
  • Python version used: 3.10.8

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

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

はじめの一歩

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

調査の方向性

まず、mypy 1.1.1 と --strict を使って最小限の Python 再現コードを実行し、Decimal ベースの NewTypes と int および str のケースを比較します。重複しない等値チェックに対する型チェックの経路を追跡してください。同等の NewTypes が一貫して期待される診断を生成し、回帰テストのカバレッジですべての比較が確認できた時点で、この issue は完了です。

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

評価

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

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

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