Skip to content

Support recursive unions in Python servers - #4770

Open
sgpthomas wants to merge 3 commits into
smithy-lang:mainfrom
sgpthomas:fix/python-server-recursive-unions
Open

Support recursive unions in Python servers#4770
sgpthomas wants to merge 3 commits into
smithy-lang:mainfrom
sgpthomas:fix/python-server-recursive-unions

Conversation

@sgpthomas

@sgpthomas sgpthomas commented Aug 6, 2026

Copy link
Copy Markdown

Motivation and Context

Smithy recursive-shape boxing correctly adds indirection to direct structure/union cycles, but Python server generation only provides PyO3 conversions for boxed structures. When the cycle requires a Box<Union>, generated PyO3 methods fail to compile because that type implements neither FromPyObject nor IntoPy<PyObject>.

Description

Extract the existing boxed-shape PyO3 conversions into a shared renderer and use it for both structures and unions. Boxed union conversion delegates through the union's existing unboxed conversion, preserving the generated Python union representation.

The regression test models a NativeValue union and ArrayValue structure that recurse directly through a required member. It generates and compiles the Python server, constructs the recursive value from Python, exercises the boxed getter, and extracts the result back into Rust.

Testing

  • :codegen-server:codegen-server-python:test --tests '*PythonServerUnionGeneratorTest'
  • Kotlin formatting and block-quote pre-commit hooks

@sgpthomas
sgpthomas marked this pull request as ready for review August 6, 2026 20:56
@sgpthomas
sgpthomas requested review from a team as code owners August 6, 2026 20:56
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.

1 participant