This modifies the provided hash method to also include the struct type. This improves hash quality for mappings or sets that contain multiple different struct types as keys, as structs of different types with the same data will now hash differently, better matching the __eq__ implementation.
As an implementation detail, structs should now hash as a tuple of the type and all following elements.
from msgspec import Struct
class Point(Struct, frozen=True):
x: int
y: int
assert hash(Point(1, 2)) == hash((Point, 1, 2))
This modifies the provided hash method to also include the struct type. This improves hash quality for mappings or sets that contain multiple different struct types as keys, as structs of different types with the same data will now hash differently, better matching the
__eq__
implementation.As an implementation detail, structs should now hash as a tuple of the type and all following elements.
Addresses part of #591.