python / python/mypy

No error emitted with `ParamSpec` on a signature that is a union of callables with `ParamSpec` and without `ParamSpec`

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

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

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

説明

Bug Report

See discussion on pyright at : https://github.com/microsoft/pyright/issues/6796

mypy doesn't emit an error, but pyright does, and it isn't clear which is correct!
We're trying to support something with pandas with DataFrame.pipe() that allows functions with any kind of argument list to be passed. But the function can be specified in one of two ways:

  • as a function
  • as a tuple, with the tuple being the name of an argument and the function

To Reproduce

from typing import Callable, Concatenate
from typing_extensions import ParamSpec

P = ParamSpec("P")


def func1(x: int):
    print(x)


def func2(x: int, /, y: str):
    print(x)


def accept_func(
    f: Callable[Concatenate[int, P], None] | tuple[int, Callable[..., None]],
    *args: P.args,
    **kwargs: P.kwargs,
) -> None:
    if isinstance(f, tuple):
        if args:
            f[1](f[0], args)
        else:
            f[1](f[0])
    else:
        f(5)


accept_func(func1)
accept_func((2, func1))
accept_func((3, func2), "abc")

Expected Behavior

pyright reports:

 pspec.py:26:9 - error: Arguments for ParamSpec "P@accept_func" are missing (reportGeneralTypeIssues)
 pspec.py:29:1 - error: Arguments for ParamSpec "P@accept_func" are missing (reportGeneralTypeIssues)
 pspec.py:30:25 - error: Arguments for ParamSpec "P@accept_func" are missing (reportGeneralTypeIssues)

pyright authors think mypy should report all 3. See discussion in linked issue.

Actual Behavior

mypy reports:

Success: no issues found in 1 source file

Your Environment

  • Mypy version used: 1.7.1
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.11.3

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

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

はじめの一歩

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

調査の方向性

提供されている ParamSpec と Callable-union の再現コードから始め、次にリンク先の pyright の議論を読んで、競合する解釈を理解してください。指定された環境で mypy に対して実行し、ParamSpec のチェック動作を追跡してください。処理が解決され、回帰テストでカバーされるか、意図したものとして文書化されれば完了です。

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

評価

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

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

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