python / python/mypy

Bad interaction between ParamSpec and TypeVarTuple

未关闭
#19,855 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

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. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

在链接的 mypy-play 示例中复现该代码片段,并比较报告的 ParamSpec 和 TypeVarTuple 诊断信息。阅读 src/trio/_core/_run.py#L1970 中引用的 Trio 入口点,以了解由此派生的用例。示例能够通过类型检查且没有不兼容的 Callable 错误,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
devtools
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。