Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import logging
from concurrent.futures import Future, ThreadPoolExecutor, wait
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, overload

from aws_durable_execution_sdk_python.context import DurableContext
from aws_durable_execution_sdk_python.exceptions import (
Expand Down Expand Up @@ -166,12 +166,39 @@ def from_durable_execution_invocation_input(
# endregion Invocation models


@overload
def durable_execution(
func: Callable[[Any, DurableContext], Any],
*,
boto3_client: Boto3LambdaClient | None = None,
plugins: list[DurableInstrumentationPluginFactory] | None = None,
) -> Callable[[Any, LambdaContext], Any]: ...


@overload
def durable_execution(
func: None = None,
*,
boto3_client: Boto3LambdaClient | None = None,
plugins: list[DurableInstrumentationPluginFactory] | None = None,
) -> Callable[
[Callable[[Any, DurableContext], Any]],
Callable[[Any, LambdaContext], Any],
]: ...


def durable_execution(
func: Callable[[Any, DurableContext], Any] | None = None,
*,
boto3_client: Boto3LambdaClient | None = None,
plugins: list[DurableInstrumentationPluginFactory] | None = None,
) -> Callable[[Any, LambdaContext], Any]:
) -> (
Callable[[Any, LambdaContext], Any]
| Callable[
[Callable[[Any, DurableContext], Any]],
Callable[[Any, LambdaContext], Any],
]
):
"""
Decorator to create a durable execution handler.

Expand Down
27 changes: 27 additions & 0 deletions packages/aws-durable-execution-sdk-python/tests/execution_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4617,6 +4617,33 @@ def test_handler(event: Any, context: DurableContext) -> dict:
return decorator(test_handler), test_handler


@durable_execution
def _bare_decorator_typed_handler(
event: Any, context: DurableContext
) -> dict[str, Any]:
"""Verify bare decorator form type checks properly."""
return {"result": "success"}


@durable_execution(plugins=[])
def _parameterized_decorator_typed_handler(
event: Any, context: DurableContext
) -> dict[str, Any]:
"""Verify parameterized decorator form type checks properly."""
return {"result": "success"}


@pytest.mark.parametrize(
"handler",
[_bare_decorator_typed_handler, _parameterized_decorator_typed_handler],
ids=["bare", "parameterized"],
)
def test_typed_decorated_handler_signature(handler) -> None:
"""Verify decorated handlers have the expected (event, context) signature."""
signature = inspect.signature(handler)
assert list(signature.parameters) == ["event", "context"]


@pytest.mark.parametrize(
"build_handler",
[_bare_decorated_handler, _plugin_decorated_handler],
Expand Down