python / python/cpython

Alias that is generic over a ParamSpec is not hashable when using a list as parameters_expression

Aperta
#124,496 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

topic-typing type-bug
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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?

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con il riproduttore nell’issue e confronta il comportamento dell’alias ParamSpec con i casi Generic, Protocol e Callable citati. Leggi PEP 612, l’issue #124445 e la discussione collegata per stabilire se i parametri lista debbano diventare tuple annidate o essere uniti. Il lavoro è completato quando hash(X[[T]]) funziona senza una lista non hashable, preservando gli argomenti previsti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
backend
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.