Skip to content

bindings/python: +fix Make Transition hashable and drop misspelled __neq__ - #896

Merged
Adda0 merged 1 commit into
develfrom
issue-853-transition-hash-pr
Oct 8, 2026
Merged

Adda0 merged 1 commit into
develfrom
issue-853-transition-hash-pr

Conversation

@Adda0

@Adda0 Adda0 commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

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

@Adda0
Adda0 marked this pull request as ready for review October 8, 2026 11:55
@greptile-apps

greptile-apps Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Fixes Python bindings for transition object behavior.

The PR appears safe to merge; no actionable issues were found.

What we checked:

  • Transition keys stay stable: Python cannot set the three fields. Returned transitions own separate copies, so changing an automaton does not change an existing key.
Summary

Makes Transition usable in sets and as dictionary keys by hashing its three fields.

  • Removes unused __neq__ methods and updates the type declarations.
  • Adds tests for equal hashes, set deduplication, dictionary keys, and inequality.
  • No actionable issues found. Tests were not run during this review.

Reviews (1) · Last reviewed commit: "bindings/python: +fix Make Transition ha..." · Reviewed by Greptile

…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
Adda0 force-pushed the issue-853-transition-hash-pr branch from cd824ee to 7b864ad Compare October 8, 2026 12:13
@Adda0
Adda0 merged commit b1821e2 into devel Oct 8, 2026
26 checks passed
@Adda0
Adda0 deleted the issue-853-transition-hash-pr branch October 8, 2026 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant