Alias that is generic over a ParamSpec is not hashable when using a list as parameters_expression
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 35.9k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Bug description:
This is slightly related to #124445, but a different issue, maybe it can be solved at the same time?
Consider the following code where [T] is a parameters_expression according to PEP 612. Similar to using Callable or using Generic[P] or Protocol[P] I would expect the following code to work and receive a hashable variable:
from typing import TypeVar
from collections.abc import Callable
type X[**P] = Callable[P, int]
T = TypeVar("T")
hash(X[[T]])
# ~~~~^^^^^^^^
# TypeError: unhashable type: 'list'
Cause:
The problem is that X[[T]].__args__ == ([T],) which cannot be hashed. I think the list should either be turned into a tuple. Either a nested one as its done for Generic and Protocol or joined like for Callable[P, str][[int]].__args__.
Discussion:
I've opened a parallel topic on discuss
CPython versions tested on:
3.13.0.rc2
Operating systems tested on:
Linux
EDIT: A thought, should this be changed for whole class in general?
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 issue 中的重現案例開始,將 ParamSpec 別名的行為與引用的 Generic、Protocol 和 Callable 案例進行比較。閱讀 PEP 612、issue #124445 以及連結的討論,以釐清列表參數應該變成巢狀 tuple,還是應該合併。完成的標準是 hash(X[[T]]) 能夠在沒有不可雜湊列表的情況下運作,同時保留預期的引數。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100