Python: preserve PEP 695 type-alias type parameters across RPC#8331
Open
shanman190 wants to merge 2 commits into
Open
Python: preserve PEP 695 type-alias type parameters across RPC#8331shanman190 wants to merge 2 commits into
shanman190 wants to merge 2 commits into
Conversation
Py.TypeAlias had no typeParameters field on the Java side, so all four RPC codecs (Python + Java, sender + receiver) dropped it. `type X[T] = ...` was silently narrowed to `type X = ...` once the tree crossed the RPC boundary — a print-fidelity loss invisible to the in-process printer suite and baked into every serialized LST. Add the field to Py.TypeAlias (JContainer<J.TypeParameter>, mirroring J.ClassDeclaration) and send/receive it between name and value in all four codecs. Both serialization formats (V2 Jackson-reflection, V3 reflective field walk) discover the new field automatically, so no moderne-cli change is needed. Verified: Python and Java RPC round-trip tests preserve simple, bound, variadic and ParamSpec parameters; numpy (3 -> 0) and home-assistant (15 -> 0) TypeAlias round-trip mismatches resolved; existing type-alias parser/printer suite green.
Space out the type parameters (before `[`, inside the brackets, around the `:` bound and the commas) so the round-trip also asserts JContainer.before and the element padding survive, not just the parameters' presence.
shanman190
marked this pull request as ready for review
July 26, 2026 02:31
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.
Py.TypeAliashad notypeParametersfield on the Java side, so all four RPC codecs (Python + Java, sender + receiver) dropped it.type X[T] = ...was silently narrowed totype X = ...once the tree crossed the RPC boundary — a print-fidelity loss invisible to the in-process printer suite and baked into every serialized LST.Change
Py.TypeAlias— add@Nullable JContainer<J.TypeParameter> typeParameters(mirroringJ.ClassDeclaration), with the unwrapped getter,withTypeParameters, andPaddingaccessors.PythonSender/PythonReceiver.visitTypeAliasand_visit_type_aliason both Python sides send/receive the container betweennameandvalue.Both serialization formats (V2 Jackson-reflection, V3 reflective field walk) discover the new field automatically, so no moderne-cli change is needed.
Verification
Python RPC round-trip test (
tests/rpc/test_type_alias_roundtrip.py) and a JavaPythonSenderReceiverRoundTripTestcase cover simple, bound (T: int), variadic (*Ts) and ParamSpec (**P) parameters, plus the no-params regression.Serialize→deserialize→print corpus: numpy 3 → 0 and home-assistant 15 → 0
TypeAliasround-trip mismatches; existing type-alias parser/printer suite green.Draft: independent of the
match-parser fix (Python: fix match-statement parse desync that corrupts trees over RPC #8330). Optional follow-up: a Java assertion for the null (no-params) path — currently covered by thegetAndSendnull-guard and the Python test.