Skip to content

Order enum values in Python and Rust - #312

Merged
matt-edmondson merged 1 commit into
mainfrom
claude/project-thread-71fapa-295
Oct 20, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
claude/project-thread-71fapa-295

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

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 Python Enum raises TypeError on <, and a Rust enum deriving only PartialEq does not compile when ordered.

After: a generated Python enum derives from IntEnum (imported from enum), and a generated Rust enum derives Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash. Enumerators compare by their declared values in both, so Level.Low < Level.High holds even when the declaration lists them out of order.

How: two lines in PythonGenerator (the import and the base class) and one in RustGenerator (the derive list). EnumOrderingTests runs 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

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
@matt-edmondson matt-edmondson self-assigned this Oct 20, 2026
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 74b21be into main Oct 20, 2026
16 checks passed
@matt-edmondson
matt-edmondson deleted the claude/project-thread-71fapa-295 branch October 20, 2026 11:45
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.

Comparing two enum values with < / <= / > / >= raises TypeError in generated Python and fails to compile (E0369) in Rust

2 participants