Skip to content

fix(sdk): add overloads for durable_execution (#921) - #935

Merged
SilanHe merged 3 commits into
aws:mainfrom
srivilliamsai:fix/durable-execution-decorator-overload
Nov 20, 2026
Merged

SilanHe merged 3 commits into
aws:mainfrom
srivilliamsai:fix/durable-execution-decorator-overload

Conversation

@srivilliamsai

Copy link
Copy Markdown
Contributor

Issue #, if available

Fixes #921

Description of changes

Add typing @overload signatures for durable_execution to support both bare decorator usage (@durable_execution) and parameterized decorator usage (e.g. @durable_execution(plugins=[...])).

Previously, durable_execution had only a single return type signature Callable[[Any, LambdaContext], Any]. When called without arguments or with keyword arguments (such as plugins=...), the function returns a decorator (functools.partial), but static type checkers (mypy) treated the returned object as an already-wrapped handler taking (event, context), raising error: Too few arguments [call-arg].

Design

See Rules for every change.

  • Design note (rule 3), for a new feature, a new option or a public API change:
    • Problem: When users decorate their Lambda handlers using @durable_execution(plugins=[...]), mypy reports error: Too few arguments [call-arg].
    • Cause: durable_execution only declared Callable[[Any, LambdaContext], Any] as its return type. At runtime, when func is None, it returns a decorator functools.partial(...) expecting the user function, which did not match the single return type hint.
    • Simpler options considered (rule 2): We considered typing func: Any = None or returning Any, but exact and narrow types are required by repository coding standards (CONTRIBUTING.md). Standard typing.overload is Python's standard mechanism for dual-form decorators.
    • Chosen option: Provide two @overload definitions for func: Callable[[Any, DurableContext], Any] and func: None = None.
    • What the change removes: Nothing removed.
  • Simpler options considered (rule 2), if the change adds logic: Not applicable; this change introduces no new runtime logic or branches, only typing overloads.
  • Root cause (rule 5), for a bug fix: Missing @overload signatures on durable_execution for the bare decorator and factory decorator forms.
  • Net change in source lines and in public API members: +28 lines in execution.py (typing overloads only), 0 new runtime public API members.

Assumptions

None outside Python typing semantics for @overload.

Decisions not covered by the issue or the design note

  • Added both bare and parameterized typed handlers to packages/aws-durable-execution-sdk-python/tests/execution_test.py to ensure both forms are statically verified by dev-core:typecheck and tested for valid parameter signatures by pytest.

Checklist

  • Every new branch has a test that fails without it (rule 4)
  • For a bug fix: the first commit adds a test that fails on the current code (rule 5)
  • Every edited test expectation is listed in the description, with the reason (rule 5) - (No existing test expectations were edited)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Adds test reproducing issue aws#921 with durable_execution typing.
Add typing overloads for bare and parameterized decorator forms.
@srivilliamsai
srivilliamsai deployed to ai-pr-review-runtime November 15, 2026 06:31 — with GitHub Actions Active
@SilanHe
SilanHe merged commit de2abab into aws:main Nov 20, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: durable_execution(plugins=...) return type fails mypy with "Too few arguments"

4 participants