Preserve type hints when decoding payload-backed generic Python models - #129
Merged
Conversation
VegetarianOrc
marked this pull request as ready for review
August 17, 2026 22:52
tconley1428
reviewed
Aug 18, 2026
| type_hint: type[typing.Any], | ||
| ) -> typing.Any: | ||
| proto = value | ||
| (_context_type,) = typing.get_args(type_hint) or (typing.Any,) |
Collaborator
There was a problem hiding this comment.
Maybe don't put _ just in case it isn't used.
tconley1428
reviewed
Aug 18, 2026
| return typing.cast( | ||
| object, | ||
| converter.from_payload(_clone_payload(proto), type_hint), | ||
| ) |
Collaborator
There was a problem hiding this comment.
Check on these casts I think.
tconley1428
reviewed
Aug 18, 2026
| (_output_type,) = typing.get_args(type_hint) or (typing.Any,) | ||
| if not proto.HasField("details"): | ||
| raise ValueError("missing required field PayloadBackedOutput.details") | ||
| details = typing.cast( |
Collaborator
There was a problem hiding this comment.
That's an awful lot of casting.
tconley1428
reviewed
Aug 18, 2026
| ) | ||
|
|
||
|
|
||
| def payloads_from_proto( |
Collaborator
There was a problem hiding this comment.
Does payloads also need to use the hint?
tconley1428
approved these changes
Aug 18, 2026
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.
Summary
Payloadfields.typing.Any.Payloadsdecoding as an untyped sequence.Motivation
Proto-backed generic models previously lost their concrete type arguments during nested decoding.
For example, decoding:
could produce dictionaries for payload-backed fields instead of EchoOutput and MyContext instances.
The generated transfer converters now extract runtime generic arguments, propagate them into nested model converters, and provide them to
Temporal’s payload converter.
Unparameterized models continue to decode successfully. They use typing.Any as the fallback instead of object, which Temporal cannot
deserialize as a type hint.
Tests
Validation