fix: Rewrite Type Handling#63
Merged
natemort merged 1 commit intocadence-workflow:mainfrom Jan 29, 2026
Merged
Conversation
598c46e to
938e916
Compare
shijiesheng
reviewed
Jan 27, 2026
cadence/activity.py
Outdated
Comment on lines
169
to
171
| def __call__( | ||
| self, fn: Union[Callable[_P1, Awaitable[_R1]], Callable[_P2, _R2]] | ||
| ) -> Union[AsyncActivityDefinition[_P1, _R1], SyncActivityDefinition[_P2, _R2]]: |
Member
There was a problem hiding this comment.
no need to specify typing in the implementation since typing is already hinted in the overload.
Member
Author
There was a problem hiding this comment.
The implementation references the various type parameters unfortunately :( .
|
|
||
| class ActivityDefinitionOptions(TypedDict, total=False): | ||
| name: str | ||
| class ActivityDefinition(Protocol[P, R]): |
Member
There was a problem hiding this comment.
why does ActivityDefinition needs to have call method? I think this is where introduced all the sync/async branches.
Member
Author
There was a problem hiding this comment.
Without __call__ we'd be transforming their functions into something that isn't Callable. They'd no longer be able to directly invoke any decorated functions
938e916 to
f705c69
Compare
shijiesheng
approved these changes
Jan 29, 2026
Move type handling logic from activity.py to fn_signature.py, providing utilities for understanding a functions parameters and converting calls/payloads to match the function's signature. Use this new logic in Workflows, to support any number of typed parameters. Rewrite the Activity decorators to be fully type-safe. Introduce `@activity.method` and `@activity.impl` to satisfy type safety while allowing for interface types or classes that contain activities. Fix type-safety for Workflows. This only addresses the annotations and doesn't provide a type-safe invocation mechanism like what is supported with Activities.
f705c69 to
318a4f0
Compare
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.
Move type handling logic from activity.py to fn_signature.py, providing utilities for understanding a functions parameters and converting calls/payloads to match the function's signature.
Use this new logic in Workflows, to support any number of typed parameters.
Rewrite the Activity decorators to be fully type-safe. Introduce
@activity.methodand@activity.implto satisfy type safety while allowing for interface types or classes that contain activities. These definitions are quite complicated for a few reasons:activity.defnandactivity.defn(), which means we need to handle both being or returning a decoratorAwaitable[T]vsT).Awaitable[T]we don't want to returnAwaitable[Awaitable[T]].__get__special method is invoked, which returns the function with theselfparameter already filled.ClassName.foothen__get__is invoked withNone, and the returned function doesn't have the filled self parameter.ActivityDefinition. Otherwise it's not a valid subclass.activity.impldecorator was added to support this. Maybe it makes more sense to call itoverride.Fix type-safety for Workflows. This only addresses the annotations and doesn't provide a type-safe invocation mechanism like what is supported with Activities. That will be explored in a future diff.
What changed?
Why?
How did you test it?
Potential risks
Release notes
Documentation Changes