Union of hashables is not hashable #8268
-
I was just trying to simplify some hints in pandas-stubs where there are 4 Hashable bound typevars in a signature that are each only used once. https://github.com/pandas-dev/pandas-stubs/blob/main/pandas-stubs/core/reshape/concat.pyi#L28 I thought that that should be easily replaceable with just using Hashable directly but this gives me an error:
Is there something i can do to resolve this or do i need to keep the four TypeVars that are each only used once here. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Pyright's behavior here is correct. This has nothing to do with unions. The first type parameter in the Here's a simplified example that demonstrates the issue: from typing import Hashable, Mapping
def func(value: Mapping[int, str]):
x: Mapping[Hashable, str] = value # Type Error Not surprisingly, mypy also generates an error with this code. |
Beta Was this translation helpful? Give feedback.
You could use a type variable with an upper bound of
Hashable
.