Non-hashable tuple should not be accepted as `Hashable`
オープン
まだ誰も着手していません。
bug
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
I'd expect to get a type error when trying to pass a tuple to a Hashable bound if that tuple contains any non-hashable element type.
To Reproduce
from typing import Hashable, TypeVar
T = TypeVar("T", bound=Hashable)
def f(x: T) -> T:
print(hash(x))
return x
def usage1(x: tuple[dict[str, str], ...]):
f(x)
def usage2(x: tuple[dict[str, str], int, int]):
f(x)
def usage3(x: tuple[int, int, dict[str, str]]):
f(x)
Expected Behavior
Type error in all f(x) lines, rejecting the non-hashable type.
Actual Behavior
The type check passes despite the unsound typing.
Your Environment
- Mypy version used: 1.16.0
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini(and other config files): - Python version used: 3.12
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供されている Python 3.12 と mypy 1.16.0 を使った再現から始め、次に Hashable の境界とタプル要素の型に関する型チェックの経路を調べます。usage1、usage2、usage3 の回帰テストカバレッジを追加します。3 つすべての呼び出しが拒否されれば作業完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- tooling
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100