Skip to content

Fix Python enum members generating tuple values#7988

Open
AayushP123 wants to merge 1 commit into
microsoft:mainfrom
AayushP123:codex/fix-python-enum-values
Open

Fix Python enum members generating tuple values#7988
AayushP123 wants to merge 1 commit into
microsoft:mainfrom
AayushP123:codex/fix-python-enum-values

Conversation

@AayushP123

@AayushP123 AayushP123 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Removes trailing commas from generated Python string enum assignments. Adds enum writer coverage for regular and escaped wire values.

A trailing comma makes a Python expression such as "red", a one-element tuple, preventing incoming string values from matching generated enum members during deserialization.

Validation

dotnet test tests/Kiota.Builder.Tests/Kiota.Builder.Tests.csproj --no-restore --nologo --filter 'FullyQualifiedName~Writers.Python.CodeEnumWriterTests' (11 passed)

Fixes #7811

@AayushP123
AayushP123 requested a review from a team as a code owner July 26, 2026 07:11
Copilot AI review requested due to automatic review settings July 26, 2026 07:11
@AayushP123 AayushP123 changed the title fix: emit Python enum members as strings Fix Python enum members generating tuple values Jul 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Python enum generation so that enum members are emitted as plain string values (instead of single-element tuples), aligning the generated output with class MyEnum(str, Enum) semantics.

Changes:

  • Update the Python CodeEnumWriter to emit enum members without a trailing comma, ensuring values are strings.
  • Strengthen Python enum writer tests to assert the absence of the trailing comma and validate correct line termination.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Kiota.Builder/Writers/Python/CodeEnumWriter.cs Removes the trailing comma so generated Python enum members are string literals, not tuples.
tests/Kiota.Builder.Tests/Writers/Python/CodeEnumWriterTests.cs Updates assertions to verify the new string-member emission and explicitly reject the old tuple syntax.

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 generator emits trailing commas on enum values, creating tuples instead of strings

2 participants