-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include the struct type in frozen hash implementation
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. ```python from msgspec import Struct class Point(Struct, frozen=True): x: int y: int assert hash(Point(1, 2)) == hash((Point, 1, 2)) ```
- Loading branch information
Showing
2 changed files
with
23 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters