Repository navigation
fix(sdk): add overloads for durable_execution (#921) - #935
Open
srivilliamsai wants to merge 2 commits into
Open
srivilliamsai wants to merge 2 commits into
srivilliamsai wants to merge 2 commits into
Conversation
Adds test reproducing issue aws#921 with durable_execution typing.
Add typing overloads for bare and parameterized decorator forms.
This branch was successfully deployed
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.
Issue #, if available
Fixes #921
Description of changes
Add typing
@overloadsignatures fordurable_executionto support both bare decorator usage (@durable_execution) and parameterized decorator usage (e.g.@durable_execution(plugins=[...])).Previously,
durable_executionhad only a single return type signatureCallable[[Any, LambdaContext], Any]. When called without arguments or with keyword arguments (such asplugins=...), the function returns a decorator (functools.partial), but static type checkers (mypy) treated the returned object as an already-wrapped handler taking(event, context), raisingerror: Too few arguments [call-arg].Design
See Rules for every change.
@durable_execution(plugins=[...]), mypy reportserror: Too few arguments [call-arg].durable_executiononly declaredCallable[[Any, LambdaContext], Any]as its return type. At runtime, whenfunc is None, it returns a decoratorfunctools.partial(...)expecting the user function, which did not match the single return type hint.func: Any = Noneor returningAny, but exact and narrow types are required by repository coding standards (CONTRIBUTING.md). Standardtyping.overloadis Python's standard mechanism for dual-form decorators.@overloaddefinitions forfunc: Callable[[Any, DurableContext], Any]andfunc: None = None.@overloadsignatures ondurable_executionfor the bare decorator and factory decorator forms.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
packages/aws-durable-execution-sdk-python/tests/execution_test.pyto ensure both forms are statically verified bydev-core:typecheckand tested for valid parameter signatures by pytest.Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.