pybind: Add __hash__ to all binding types - #627
Merged
Merged
Conversation
deustis
marked this pull request as ready for review
May 13, 2026 04:49
jmr
requested changes
May 13, 2026
jmr
left a comment
Member
There was a problem hiding this comment.
Similar for the rest of the classes.
Contributor
Author
|
Updated The remaining four — |
Contributor
Author
jmr
reviewed
May 20, 2026
This was referenced May 20, 2026
jmr
reviewed
May 21, 2026
deustis
force-pushed
the
deustis/fix_hash_bindings
branch
from
May 22, 2026 15:46
a2e57e6 to
040dd76
Compare
deustis
force-pushed
the
deustis/fix_hash_bindings
branch
from
May 22, 2026 21:15
040dd76 to
1b627a2
Compare
Member
|
This has merge conflicts, otherwise LGTM. |
In Python 3, defining __eq__ without __hash__ sets __hash__ = None, making the type unhashable. All seven affected types raised: TypeError: unhashable type: 's2geometry_bindings.S1Angle' Adds __hash__ to S1Angle, S1Interval, R1Interval, R2Point, R2Rect, S2LatLng, and S2Point using absl::Hash on their underlying values.
These types already define AbslHashValue, so absl::HashOf(self) is more idiomatic than manually extracting and hashing fields.
Use AbslHashValue free functions in the respective headers so that the Python bindings can call absl::HashOf(self) uniformly instead of manually assembling a std::pair/tuple over the component fields.
…2Rect Uses absl::VerifyTypeImplementsAbslHashCorrectly to confirm the newly added AbslHashValue functions satisfy the hash contract.
deustis
force-pushed
the
deustis/fix_hash_bindings
branch
from
May 26, 2026 15:14
1b627a2 to
918290e
Compare
Contributor
Author
Rebased |
jmr
approved these changes
May 29, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In Python 3, defining
__eq__without__hash__implicitly sets__hash__ = None, making the type unhashable. All seven affected types raised:Adds
__hash__toS1Angle,S1Interval,R1Interval,R2Point,R2Rect,S2LatLng, andS2Pointusingabsl::Hashon their underlying values.