Skip to content

Spell a Python enum value that names an escaped sibling by its escaped name [patch] - #380

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/378-python-enum-sibling-keyword
Nov 4, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/378-python-enum-sibling-keyword

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #378

What was wrong

The Python generator escaped a keyword-named enum member where it was declared (None became None_), but it wrote each member's value text unchanged. A value that names that sibling, like Default = None, still named the Python keyword. The (origin) + n that a later member derives from it did the same. The result was that Default was bound to Python's None, or the module failed on import with TypeError.

Change

PythonGenerator.GenerateEnumDeclaration now passes each value through RenameSiblingMembers, 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 string EnumMemberValues yields.

Tests

  • New ReservedWordIdentifierTests.Python_EnumValueNamingAnEscapedSiblingRunsAndResolves:
    • asserts the output contains Default = None_ and Next = (None_) + 1
    • runs the module under python3 and checks Access.Default == Access.None_ and Access.Next == 1
  • The new test fails with the generator change reverted, on Assert.Contains("Default = None_"), and passes with it.
  • Full Coder.Test suite: 1552 passed, 0 failed.

Generated by Claude Code

…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
@sonarqubecloud

Copy link
Copy Markdown

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.

Python: an enum member whose value names a keyword-escaped sibling (Default = None) still writes the keyword, so the module fails on import

2 participants