python / python/mypy

Bad interaction between ParamSpec and TypeVarTuple

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

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

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

説明

This should type check, but

from typing import Callable, TypeVarTuple

def run[T, **P](fn: Callable[P, T], *args: P.args, **kwargs: P.kwargs) -> T: ...
def coroutine_or_error[*Us](async_fn: Callable[[*Us], int], *args: *Us) -> int: ...

def test[*Ts](async_fn: Callable[[*Ts], int], args: tuple[*Ts]) -> None:
    run(coroutine_or_error, async_fn, *args)

https://mypy-play.net/?mypy=latest&python=3.12&gist=e43aee5d75dd536ed2529b3dc052e630 gives

Argument 1 to "run" has incompatible type "Callable[[Callable[[VarArg(*Us)], int], VarArg(*Us)], int]"; expected "Callable[[Callable[[VarArg(*Ts)], int], VarArg(object)], int]"  [arg-type]

Example derived from https://github.com/python-trio/trio/blob/f1039299644dfaf6dcd60ed29a4a3a51494d09a4/src/trio/_core/_run.py#L1970

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

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

はじめの一歩

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

調査の方向性

リンクされた mypy-play の例でスニペットを再現し、報告された ParamSpec と TypeVarTuple の診断を比較します。派生したユースケースを理解するため、参照されている Trio のエントリポイント src/trio/_core/_run.py#L1970 を読んでください。例が互換性のない Callable エラーなしで型チェックを通れば完了です。

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

評価

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

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

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