python / python/cpython

ParamSpec(bound=None) incorrectly sets __bound__ to NoneType

未關閉
#142,750 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

stdlib topic-typing type-bug
主要語言
Python
星號
77.2k
分支
36k
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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 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

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。