Use IntEnum instead of Enum for enum class wrappers#222
Use IntEnum instead of Enum for enum class wrappers#222timosachsenberg merged 1 commit intomasterfrom
Conversation
Change the generated Python enum wrappers to inherit from IntEnum instead of Enum. This fixes a bug where set parameters containing enum class values would fail with "TypeError: an integer is required" when iterating. The issue was that: 1. Generated code declares `cdef int item0` for iteration 2. But iterating over a set of Enum values yields Enum objects, not ints 3. Cython cannot assign an Enum object to `cdef int` With IntEnum: - Enum values ARE integers (isinstance(val, int) is True) - Cython's `cdef int` can directly accept IntEnum values - Round-trip operations (get → set) work correctly - Backwards compatible with code expecting integers Tested with pyOpenMS which uses `cdef enum class ActivationMethod`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
WalkthroughThe pull request modifies enum handling in code generation by changing the imported alias from Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
🔇 Additional comments (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
IntEnuminstead ofEnumProblem
When using
cdef enum class(C++ scoped enum) with set parameters, the generated Cython code would fail:With plain
Enum:Enummembers are NOT integersint(MyEnum.A)throwsTypeError.valueworks to get the integerSolution
Use
IntEnuminstead:IntEnummembers ARE integers (isinstance(val, int)is True)cdef intcan directly acceptIntEnumvaluesTesting
Tested with pyOpenMS which uses
cdef enum class ActivationMethodin Precursor.pxd. The test that was previously failing (testPrecursor) now passes.🤖 Generated with Claude Code
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.