Skip to content

[Feature Request] Adding type checking on workflow_execute activity when a variable number of positional args exist in the callable activity #779

@spacether

Description

@spacether

Is your feature request related to a problem? Please describe.

How about adding type checking on workflow_execute activity when a variable number of positional args exist in the callable activity?
Right now the args are not type checked, Sequence[Any] is allowed in

Describe the solution you'd like

Use TypedVarTupe to define *args, delete the arg input.

Additional context

I got this working with this code which would go in the workflow module

Ts = typing.TypeVarTuple("Ts")

async def execute_activity(
    activity: Union[
        typing.Callable[[*Ts], ReturnType],
        typing.Callable[[], ReturnType],
    ],
    *args: *Ts,
    task_queue: Optional[str] = None,
    result_type: Optional[Type] = None,
    schedule_to_close_timeout: Optional[timedelta] = None,
    schedule_to_start_timeout: Optional[timedelta] = None,
    start_to_close_timeout: Optional[timedelta] = None,
    heartbeat_timeout: Optional[timedelta] = None,
    retry_policy: Optional[temporalio.common.RetryPolicy] = None,
    cancellation_type: ActivityCancellationType = ActivityCancellationType.TRY_CANCEL,
    activity_id: Optional[str] = None,
    versioning_intent: Optional[VersioningIntent] = None,
) -> ReturnType:

Pros:

  • this works and enforces type checking for one or more positional argument inputs

Cons:

  • it only works for Python 3.11 or 3.12 and higher
  • it is a breaking change and I think requires remove of the arg argument in workflow.execute_activity

See https://stackoverflow.com/questions/79476595/is-it-possible-to-type-hint-a-callable-that-takes-positional-arguments-only-usin

Other Apllications

  • a fix like this would be great for signals, updates, and queries too

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions