Repository navigation
Order enum values in Python and Rust - #312
Merged
Merged
Conversation
A Python enum now derives from IntEnum and a Rust enum derives PartialOrd, Ord and Hash, so comparing two enumerators by their declared values works in both targets as it already does in the others. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014YYYK5TCGFXNo5ofZckGoo
|
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.



Requested by Matt · project thread
Fixes #295.
Before: comparing two enumerators with
<,<=,>or>=worked in the C-family targets but not in Python or Rust. A PythonEnumraisesTypeErroron<, and a Rust enum deriving onlyPartialEqdoes not compile when ordered.After: a generated Python enum derives from
IntEnum(imported fromenum), and a generated Rust enum derivesClone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash. Enumerators compare by their declared values in both, soLevel.Low < Level.Highholds even when the declaration lists them out of order.How: two lines in
PythonGenerator(the import and the base class) and one inRustGenerator(the derive list).EnumOrderingTestsruns generated Python and compiles and runs generated Rust over an enum declared out of value order, asserting all four comparisons. Both tests fail without the change.Generated by Claude Code