Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Daraan opened this issue Sep 25, 2024 · 0 comments
Labels
topic-typing type-bug An unexpected behavior, bug, or error

Comments

@Daraan
Copy link
Contributor

Daraan commented Sep 25, 2024

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?

@Daraan Daraan added the type-bug An unexpected behavior, bug, or error label Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-typing type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants