ParamSpec(bound=None) incorrectly sets __bound__ to NoneType
未关闭
还没有人认领这个 Issue。
stdlib
topic-typing
type-bug
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
When creating a ParamSpec with bound=None, the runtime bound attribute is set to <class 'NoneType'> instead of None.
How to reproduce
from typing import ParamSpec, Callable
P1 = ParamSpec("P")
P2 = ParamSpec("P", bound=None)
P3 = ParamSpec("P", bound=Callable[[int, str], float])
def check_bound(label, p, expected):
got = p.__bound__
ok = (got is expected)
exp_s = repr(expected)
got_s = repr(got)
print(f"{label}.__bound__ should be {exp_s}, got {got_s} -> {'OK' if ok else 'FAIL'}")
check_bound("P1", P1, None)
check_bound("P2", P2, None)
check_bound("P3", P3, Callable[[int, str], float])
Current behavior
d:\MyCode\cpython\PCbuild\amd64>python_d.exe py_bound.py
P1.__bound__ should be None, got <class 'NoneType'> -> FAIL
P2.__bound__ should be None, got <class 'NoneType'> -> FAIL
P3.__bound__ should be typing.Callable[[int, str], float], got typing.Callable[[int, str], float] -> OK
CPython versions tested on:
CPython main branch
Operating systems tested on:
Windows
Linked PRs
- gh-142751
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 ParamSpec 的实现开始,并在 CPython main 上运行提供的复现代码。验证未绑定的 ParamSpec 和使用 bound=None 创建的 ParamSpec 将 bound 暴露为 None,而显式绑定的 ParamSpec 会保留其 bound;该 issue 链接到了 PR gh-142751,因此请先查看这项工作。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 20/100