python / python/mypy

erroneous complaint that overloaded function implementation does not accept all possible arguments of signature

未关闭
#18,596 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug false-positive topic-overloads
主要语言
Python
星标
20.6k
派生
3.3k
PR 合并指标
PR 指标待抓取

描述

Bug Report

Erroneous complaint that overloaded function implementation does not accept all possible arguments of signature.

To Reproduce

from datetime import datetime
from typing import overload

class Sample:

    @overload
    @classmethod
    def set(cls, year: int) -> None:
        ...

    @overload
    @classmethod
    def set(cls, instance: datetime, / ) -> None:
        ...

    @classmethod
    def set(cls, *args: datetime | int, **kw: int) -> None:
        pass

Expected Behavior

The above should pass type checking.

Pyright's happy enough:

$ pyright typing_bug.py 
0 errors, 0 warnings, 0 informations 

Actual Behavior

$ mypy typing_bug.py 
typing_bug.py:16: error: Overloaded function implementation does not accept all possible arguments of signature 1  [misc]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.14.1 (compiled: yes)
  • Mypy command-line flags: None, see above
  • Mypy configuration options from mypy.ini (and other config files): None.
  • Python version used: Python 3.12.1

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

使用 mypy 1.14.1 重现 typing_bug.py 中的报告,并将结果与 pyright 进行比较。跟踪 classmethod 示例的 overload 实现兼容性检查;完成的标准是 mypy 接受所示代码且不再给出错误的投诉,同时保留对不兼容实现的有效诊断。

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

评估

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

把新 issue 发到你的邮箱

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