Possible bug: `*tuple[int, *tuple[Any, ...]]` is not treated as unbounded like `*tuple[*tuple[Any, ...]]` is (and `*tuple[Any, ...]` by itself) (passes pyright 1.1.414 , pyrefly 1.3.1)
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 58/100
調査の方向性
Start by running the f, f2, and f3 examples from the issue in the MyPy Playground and inspect how unpacked tuple types are matched. Compare the handling of *tuple[Any, ...] and *tuple[int, *tuple[Any, ...]] with the cited typing specification. Done means the intended unbounded behavior is confirmed or corrected, with regression coverage for the reported Tuple index out of range case.
索引モデルが issue の本文から書いたものです。
説明
Hello MyPy team!
I am seeing error: Tuple index out of range [misc] in a case where it seems inappropriate (and it passes pyright 1.1.414 , pyrefly 1.3.1), where MyPy appears to be handling unpacked unbounded type tuples inconsistently:
*tuple[int, *tuple[Any, ...]] is not treated as unbounded like *tuple[*tuple[Any, ...]] is (and *tuple[Any, ...] by itself).
In the following example (try it online in the MyPy Playground at https://mypy-play.net/?gist=0ce2970c7a6472603d696e130beeabcc ),
f and f2 pass, but f3 fails MyPy with error: Tuple index out of range [misc]:
# e.g. python 3.12, mypy 2.3.1
# passes pyright 1.1.414 , pyrefly 1.3.1
from typing import Any
# see https://peps.python.org/pep-0646/#unpacking-unbounded-tuple-types#:~:text=Note%20that%20Tuple
# this one is handled properly
def f(*args: *tuple[*tuple[Any, ...]]) -> None:
reveal_type(args[0]) # Any
reveal_type(args[1]) # Any
# this is also handled properly
def f2(*args: *tuple[int, *tuple[Any, int]]) -> None:
reveal_type(args[1]) # Any
# but *args is not recognized as unbounded here?
# there seems to be general support for such forms for some kinds of type matching recognizing the unboundedness, see e.g. the example at https://web.archive.org/web/20260918002706/https://typing.python.org/en/latest/spec/generics.html#:~:text=type%20and%20a%20part%20of%20an%20arbitrary-length%20tuple
def f3(*args: *tuple[int, *tuple[Any, ...]]) -> None:
reveal_type(args[1]) # error: `Tuple index out of range [misc]`, seems it should be recognized as unbounded like in f, why is this considered ambiguous?
Thanks in advance!
It is also fine just to confirm the expected behavior without promising any fix, I would be happy to write test cases and attempt a fix myself. I am trying to understand the intended behavior here in part to evaluate solutions to https://github.com/python/mypy/issues/21998 (my own and potentially others, e.g. see below).
cc/ @00200200 as the intended behavior here would affect their PR at https://github.com/python/mypy/pull/22002 .
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- 平均マージ
- 1日 9時間
- マージ済み PR(30日)
- 56
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/mypy のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
bug topic-configuration topic-error-reporting
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
bug topic-attrs
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
syfoud/Simulated_Scepter#172 ·
-
A cancelled tests run makes the coverage comment workflow fail and reports it as a red check on main オープンarea: ci bug perceived difficulty: 3
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Nitjsefnie-Harness-Commons/daedalus#921 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
EleutherAI/lm-evaluation-harness#4207 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
ClickHouse/clickhouse-connect#1057 ·