Alias that is generic over a ParamSpec is not hashable when using a list as parameters_expression
まだ誰も着手していません。
- 主要言語
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Issue の再現コードから始め、ParamSpec エイリアスの動作を、参照されている Generic、Protocol、Callable のケースと比較してください。リストパラメーターをネストしたタプルにするべきか、結合するべきかを判断するために、PEP 612、issue #124445、およびリンクされたディスカッションを読んでください。hash(X[[T]]) が hash 化できないリストなしで動作し、意図された引数を保持できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100