python / python/mypy

`Iterator[int]` not recognised as `Hashable`

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

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

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

説明

Bug Report

Iterator[int] is not recognised as Hashable.

To Reproduce

from collections.abc import Sequence, Hashable

class DataFrame:
    def __setitem__(
        self, key: tuple[slice, Hashable], value: Sequence[int]
    ) -> None: ...

# mypy and ty error, pyrefly and pyright pass
DataFrame().__setitem__((slice(None, None, None), iter([0])), [1])
DataFrame()[:, iter([0])] = [1]

Expected Behavior

error free

Actual Behavior

main.py:9: error: Invalid index type "tuple[slice[Any, Any, Any], Iterator[int]]" for "DataFrame"; expected type "tuple[slice[Any, Any, Any], Hashable]"  [index]
main.py:10: error: Invalid index type "tuple[slice[None, None, None], Iterator[int]]" for "DataFrame"; expected type "tuple[slice[Any, Any, Any], Hashable]"  [index]
Found 2 errors in 1 file (checked 1 source file)

Your Environment

Playground

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

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

はじめの一歩

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

調査の方向性

リンクされた mypy playground の main.py 再現コードから始め、mypy を実行して無効なインデックスタイプの診断を確認します。Iterator[int] が Hashable に対してどのようにチェックされるかを追跡し、その後、期待されるタプルのインデックスタイプを保持したまま再現コードにエラーがないことを確認します。

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

評価

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

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

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