Skip to content

fix(python): preserve boolean const discriminators in RPC codegen - #2162

Closed
syf2211 wants to merge 1 commit into
github:mainfrom
syf2211:fix/python-boolean-discriminator-unions
Closed

fix(python): preserve boolean const discriminators in RPC codegen#2162
syf2211 wants to merge 1 commit into
github:mainfrom
syf2211:fix/python-boolean-discriminator-unions

Conversation

@syf2211

@syf2211 syf2211 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix Python RPC codegen so JSON boolean const discriminator values are preserved instead of being coerced to strings. This restores decoding for SessionListEntry (isRemote) and QueuedCommandResult (handled).

Motivation

sessions.list() raised ValueError for any non-empty session list because the generated dispatcher matched case "true": / case "false": against Python bool values. QueuedCommandHandled.to_dict() also serialized handled as the string "true" instead of JSON boolean true.

Fixes #2122

Changes

  • Add PyDiscriminatorValue helpers in scripts/codegen/python.ts to emit True/False match patterns and ClassVar[bool] defaults
  • Regenerate python/copilot/generated/rpc.py
  • Add unit tests covering boolean union decode/encode and SessionList.from_dict

Tests

cd python && python3 -m pytest test_rpc_generated.py -q

Result: 3 passed

Notes

  • String-discriminated unions are unchanged (JSON.stringify path preserved)
  • Go codegen already handled booleans correctly; Python was the only affected binding
  • composer-2.5 review: APPROVE

Boolean JSON schema const values were coerced to strings during Python
codegen, breaking match dispatchers for SessionListEntry and
QueuedCommandResult. Preserve bool consts and emit True/False patterns
and ClassVar[bool] defaults, matching the Go generator behavior.

Fixes github#2122
@syf2211
syf2211 requested a review from a team as a code owner July 30, 2026 12:08
@SteveSandersonMS

Copy link
Copy Markdown
Contributor

Thanks for the fix. This duplicates #2123, which addresses the same Python boolean-discriminator codegen bug with broader test coverage and is the version we plan to proceed with, so I’m closing this PR in favor of #2123.

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: boolean-discriminated unions never decode - sessions.list() raises for any non-empty result

2 participants