Return snake-cased member name from str() on enum values#135
Merged
jhonabreul merged 4 commits intoJul 10, 2026
Conversation
Enum members are exposed to Python with upper-cased snake case names (e.g. FileAccess.READ_WRITE), but str() on an enum value returned the C# member name from Enum.ToString() (e.g. ReadWrite). str() and f-string formatting now return the same Python-facing snake-cased name used to access the member. Flags combinations keep the comma-separated format with each name snake-cased, and values without a defined member keep the raw numeric representation. String equality comparison now accepts the snake-cased name as well, consistently with str(), while still matching the C# member name.
Open
11 tasks
Martin-Molinero
approved these changes
Jul 10, 2026
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.
Description
C# enum members are exposed to Python with upper-cased snake case names (e.g.
FileAccess.READ_WRITE), but converting an enum value to a string returned the C# member name fromEnum.ToString()(e.g."ReadWrite"), so the string representation did not round-trip with how the member is accessed from Python.EnumObjectnow overrides thetp_strslot so thatstr()(and f-string formatting) return the same Python-facing snake-cased name used to access the member:String equality comparison also accepts the snake-cased name now, consistently with
str(), while still matching the C# member name:Note this is a behavior change for code that logs, serializes or compares
str(enum_value)expecting the C# member name.Includes the version bump to 2.0.61.