Skip to content

Remove custom slice hashing workaround (post Python 3.11 drop)#2196

Merged
ricardoV94 merged 1 commit into
pymc-devs:mainfrom
jaanerik:cleanup-slice-hashing
Jun 5, 2026
Merged

Remove custom slice hashing workaround (post Python 3.11 drop)#2196
ricardoV94 merged 1 commit into
pymc-devs:mainfrom
jaanerik:cleanup-slice-hashing

Conversation

@jaanerik
Copy link
Copy Markdown
Contributor

@jaanerik jaanerik commented Jun 5, 2026

Description

Now that the minimum supported Python is 3.12 (slices became hashable in 3.12), the custom slice-hashing workaround in subtensor.py is no longer needed.

This removes:

  • BaseSubtensor._hashable_idx_list() — converted slices to tuples for hashing
  • BaseSubtensor.__hash__ — the custom hash that used the above
  • The four __hash__ = BaseSubtensor.__hash__ assignments on Subtensor, IncSubtensor, AdvancedSubtensor, and AdvancedIncSubtensor

Hashing and equality are now auto-generated by MetaType from each class's __props__, exactly as before the workaround was needed.

The custom __hash__ methods on AdvancedSubtensor1 / AdvancedIncSubtensor1 are unrelated to slice hashing and are intentionally left untouched.

Closes #1888

Verification

  • Hash/equality/set-dedup of all four ops with slice idx_lists confirmed
  • Graph build + eval for basic, advanced, and inc indexing confirmed
  • tests/tensor/rewriting/test_subtensor.py: 174 passed, 2 skipped
  • ruff check / ruff format --check: clean

🤖 Generated with Claude Code

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
Copy link
Copy Markdown
Member

mypy failure seems unrelated.

Thanks @jaanerik

@ricardoV94 ricardoV94 merged commit 4ed3aff into pymc-devs:main Jun 5, 2026
65 of 66 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Cleanup] Replace custom slice hashing with hash() (Post-Python 3.11)

2 participants