Skip to content

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

Open
@Daraan

Description

@Daraan

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions