Repository navigation
bindings/python: +fix Make Transition hashable and drop misspelled __neq__ - #896
Merged
Merged
Conversation
Adda0
marked this pull request as ready for review
October 8, 2026 11:55
|
…neq__
Transition defined __eq__ without __hash__, which under Cython 3 (like in Python) sets
__hash__ to None, so transitions raised TypeError: unhashable type when put into a set or
used as a dictionary key. Transition exposes no setters, so its instances are immutable and
can be hashed safely: __hash__ now returns hash((source, symbol, target)), consistent with
__eq__. The __neq__ methods on Transition and SymbolPost were dead code -- Python calls
__ne__, and != already follows from __eq__ -- and are removed, along with their entries in
the .pyi stub. SymbolPost deliberately stays unhashable: its symbol and targets setters make
instances mutable.
New test test_transition_hashing in bindings/python/tests/test_nfa.py checks equal hashes,
set deduplication (len({first, second, other}) == 2), dict keying and !=. It fails with
TypeError before the fix. just bindings::python::test: 132 passed, 3 skipped, 2 xfailed.
Fixes #853.
Adda0
force-pushed
the
issue-853-transition-hash-pr
branch
from
October 8, 2026 12:13
cd824ee to
7b864ad
Compare
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.
Transition defined eq without hash, which under Cython 3 (like in Python) sets
hash to None, so transitions raised TypeError: unhashable type when put into a set or
used as a dictionary key. Transition exposes no setters, so its instances are immutable and
can be hashed safely: hash now returns hash((source, symbol, target)), consistent with
eq. The neq methods on Transition and SymbolPost were dead code -- Python calls
ne, and != already follows from eq -- and are removed, along with their entries in
the .pyi stub. SymbolPost deliberately stays unhashable: its symbol and targets setters make
instances mutable.
New test test_transition_hashing in bindings/python/tests/test_nfa.py checks equal hashes,
set deduplication (len({first, second, other}) == 2), dict keying and !=. It fails with
TypeError before the fix. just bindings::python::test: 132 passed, 3 skipped, 2 xfailed.
Fixes #853.
Fixes #853