False positive in `dict.update` with variadic tuple keys

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

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

評価

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

調査の方向性

Start by running the four-line snippet in the issue (the d.update({(*prefix, 0, n): 1 ...}) case) against a local build to reproduce the no-matching-overload error. The payload does not name the source files, so locate the contextual inference for dict comprehensions and the handling of variadic tuple keys. Done means the snippet type-checks cleanly with no new errors in the existing test suite.

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

説明

typechecking
Describe the Bug

Actual: no-matching-overload

The comprehension is inferred as dict[tuple[*tuple[int, ...], int, str], int], and dict[tuple[*tuple[int, ...], int, str], int] cannot be assigned to SupportsKeysAndGetItem[tuple[*tuple[int, ...], str], int] (this protocol is invariant in the key type).

Expected: Contextual inference should allow the comprehension to be typed as dict[Key, int]. ty 0.0.107 accepts this example.

type Key = tuple[*tuple[int, ...], str]
prefix: tuple[int, ...] = (1, 2, 3)
d: dict[Key, int] = {}
d.update({(*prefix, 0, n): 1 for n in ("train", "test")})
ERROR sandbox.py:4:9-58: No matching overload found for function `typing.MutableMapping.update` called with arguments: (dict[tuple[*tuple[int, ...], int, str], int]) [no-matching-overload]
  Possible overloads:
    (m: SupportsKeysAndGetItem[tuple[*tuple[int, ...], str], int], /) -> None [closest match]
    (m: Iterable[tuple[tuple[*tuple[int, ...], str], int]], /) -> None
  Argument `dict[tuple[*tuple[int, ...], int, str], int]` is not assignable to parameter `m` with type `SupportsKeysAndGetItem[tuple[*tuple[int, ...], str], int]` in function `typing.MutableMapping.update`
Sandbox Link

https://pyrefly.org/sandbox/?project=v2.fVTNysIwEHyVpb1ECcnnJ17yCoJ48WQ9VBu1oG1pE1FK393ppgqKegr52c3Ozux8s8zeTWhub_jUeUzLehwWdFiSUmrDcgGeCi3Ir2Z49bxGnJhI-pc0BRmZoQzutkZCCdZcf912OFe-wlBb0YpxSCTpT1IxMjShnmYQXJBIIgcagFuiAz2wJBp1SAuY3uWnJpQc0wqb3N2eE8SuwSNV1ucUburPW1sLVIsaWJvA8OA5qH2fRAt-Zai9dkOn33iOaRkOaGgZHA4COXj4KH5VSRHDQi0dnasao_UjvKwP2hY6K3eNfonQjDW9pDm782s6KlmXDdJ-FtiMq_xF8h0

(Only applicable for extension issues) IDE Information

No response

主要言語
Rust
スター
7.2k
フォーク
578
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

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

facebook/pyrefly のほかの issue

facebook/pyrefly の issue をすべて見る

似ている issue

Rust の issue をもっと見る

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

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