Erroneous arg-type error with Mapping and reversed Mapping
未关闭
还没有人认领这个 Issue。
bug
- 主要语言
- Python
- 星标
- 20.6k
- 派生
- 3.3k
- PR 合并指标
- PR 指标待抓取
描述
I get an arg-type error in MyPy 1.14.1 on the following code using a Union of inverted collections.abc.Mapping:
from collections.abc import Mapping
def fun(x: Mapping[str, int | None] | Mapping[int | None, str]):
pass
fun({"a": 1, "b": 2})
fun({"a": 1, "b": 2, "c": None})
fun({1: "a", 2: "b"})
fun({1: "a", 2: "b", None: "c"})
The error is:
mypy_type_error.py:12: error: Argument 1 to "fun" has incompatible type "dict[int, str]"; expected "Mapping[str, int | None] | Mapping[int | None, str]" [arg-type]
That is, MyPy takes issue with the parameters in the third function call. The last call including the None key does not produce an error, though. I'd expect the third call to not show an error, either.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先使用 MyPy 1.14.1 运行报告中的代码片段,并比较四次调用。然后跟踪参数类型检查和 union-of-Mapping 的处理,以找到相关的回归测试区域;完成的标准是第三次调用与第四次调用一样能够稳定地被接受,同时不使其他示例出现回归。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- devtools
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 42/100