Repository navigation
Spell a Python enum value that names an escaped sibling by its escaped name [patch] - #380
Merged
Merged
Conversation
…d name [patch] The Python generator escaped a keyword-named enumeration member at its declaration (None becomes None_), but wrote each member's value as given. A value naming that sibling, such as Default = None, still named the keyword, and so did the (origin) + n a following member derives from it, so the module bound Default to Python's None or failed on import with TypeError. Values now go through RenameSiblingMembers, as the C, Go, Rust and JavaScript generators already do, spelling only the siblings that are keywords. Fixes #378. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5dEbev8THG3hgbjqS
|
This was referenced Oct 30, 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.



Fixes #378
What was wrong
The Python generator escaped a keyword-named enum member where it was declared (
NonebecameNone_), but it wrote each member's value text unchanged. A value that names that sibling, likeDefault = None, still named the Python keyword. The(origin) + nthat a later member derives from it did the same. The result was thatDefaultwas bound to Python'sNone, or the module failed on import withTypeError.Change
PythonGenerator.GenerateEnumDeclarationnow passes each value throughRenameSiblingMembers, the same helper the C, Go, Rust and JavaScript generators already use. It rewrites only the siblings whose names are keywords. This covers both explicit values and derived ones, since both come from the stringEnumMemberValuesyields.Tests
ReservedWordIdentifierTests.Python_EnumValueNamingAnEscapedSiblingRunsAndResolves:Default = None_andNext = (None_) + 1python3and checksAccess.Default == Access.None_andAccess.Next == 1Assert.Contains("Default = None_"), and passes with it.Coder.Testsuite: 1552 passed, 0 failed.Generated by Claude Code