Remove custom slice hashing workaround (post Python 3.11 drop)#2196
Merged
Conversation
Slice objects are hashable since Python 3.12, which is now the minimum supported version. Remove the BaseSubtensor._hashable_idx_list utility, its custom __hash__, and the per-subclass __hash__ = BaseSubtensor.__hash__ assignments, letting MetaType auto-generate __hash__ from __props__. Closes pymc-devs#1888 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ricardoV94
approved these changes
Jun 5, 2026
Member
|
mypy failure seems unrelated. Thanks @jaanerik |
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.
Description
Now that the minimum supported Python is 3.12 (slices became hashable in 3.12), the custom slice-hashing workaround in
subtensor.pyis no longer needed.This removes:
BaseSubtensor._hashable_idx_list()— converted slices to tuples for hashingBaseSubtensor.__hash__— the custom hash that used the above__hash__ = BaseSubtensor.__hash__assignments onSubtensor,IncSubtensor,AdvancedSubtensor, andAdvancedIncSubtensorHashing and equality are now auto-generated by
MetaTypefrom each class's__props__, exactly as before the workaround was needed.The custom
__hash__methods onAdvancedSubtensor1/AdvancedIncSubtensor1are unrelated to slice hashing and are intentionally left untouched.Closes #1888
Verification
idx_lists confirmedtests/tensor/rewriting/test_subtensor.py: 174 passed, 2 skippedruff check/ruff format --check: clean🤖 Generated with Claude Code