|
12 | 12 | from enum import Enum |
13 | 13 | from typing import TYPE_CHECKING, Generic, Self, TypeVar |
14 | 14 |
|
| 15 | +from aws_durable_execution_sdk_python.config import ChildConfig |
15 | 16 | from aws_durable_execution_sdk_python.exceptions import ( |
16 | 17 | InvalidStateError, |
17 | 18 | SuspendExecution, |
|
23 | 24 | if TYPE_CHECKING: |
24 | 25 | from collections.abc import Callable |
25 | 26 |
|
26 | | - from aws_durable_execution_sdk_python.config import ChildConfig, CompletionConfig |
| 27 | + from aws_durable_execution_sdk_python.config import CompletionConfig |
27 | 28 | from aws_durable_execution_sdk_python.lambda_service import OperationSubType |
28 | 29 | from aws_durable_execution_sdk_python.serdes import SerDes |
29 | 30 | from aws_durable_execution_sdk_python.state import ExecutionState |
@@ -92,7 +93,7 @@ def from_dict(cls, data: dict) -> BatchItem[R]: |
92 | 93 |
|
93 | 94 |
|
94 | 95 | @dataclass(frozen=True) |
95 | | -class BatchResult(Generic[R], BatchResultProtocol[R]): |
| 96 | +class BatchResult(Generic[R], BatchResultProtocol[R]): # noqa: PYI059 |
96 | 97 | all: list[BatchItem[R]] |
97 | 98 | completion_reason: CompletionReason |
98 | 99 |
|
@@ -353,10 +354,7 @@ def should_complete(self) -> bool: |
353 | 354 | # Impossible to succeed condition |
354 | 355 | # TODO: should this keep running? TS doesn't currently handle this either. |
355 | 356 | remaining_tasks = self.total_tasks - self.success_count - self.failure_count |
356 | | - if self.success_count + remaining_tasks < self.min_successful: |
357 | | - return True |
358 | | - |
359 | | - return False |
| 357 | + return self.success_count + remaining_tasks < self.min_successful |
360 | 358 |
|
361 | 359 | def is_all_completed(self) -> bool: |
362 | 360 | """True if all tasks completed successfully.""" |
@@ -493,11 +491,7 @@ def __init__( |
493 | 491 | self._suspend_exception: SuspendExecution | None = None |
494 | 492 |
|
495 | 493 | # ExecutionCounters will keep track of completion criteria and on-going counters |
496 | | - min_successful = ( |
497 | | - self.completion_config.min_successful |
498 | | - if self.completion_config.min_successful |
499 | | - else len(self.executables) |
500 | | - ) |
| 494 | + min_successful = self.completion_config.min_successful or len(self.executables) |
501 | 495 | tolerated_failure_count = self.completion_config.tolerated_failure_count |
502 | 496 | tolerated_failure_percentage = ( |
503 | 497 | self.completion_config.tolerated_failure_percentage |
@@ -532,9 +526,7 @@ def execute( |
532 | 526 | "▶️ Executing concurrent operation, items: %d", len(self.executables) |
533 | 527 | ) |
534 | 528 |
|
535 | | - max_workers = ( |
536 | | - self.max_concurrency if self.max_concurrency else len(self.executables) |
537 | | - ) |
| 529 | + max_workers = self.max_concurrency or len(self.executables) |
538 | 530 |
|
539 | 531 | self.executables_with_state = [ |
540 | 532 | ExecutableWithState(executable=exe) for exe in self.executables |
@@ -588,7 +580,7 @@ def should_execution_suspend(self) -> SuspendResult: |
588 | 580 | ) = None |
589 | 581 |
|
590 | 582 | for exe_state in self.executables_with_state: |
591 | | - if exe_state.status in (BranchStatus.PENDING, BranchStatus.RUNNING): |
| 583 | + if exe_state.status in {BranchStatus.PENDING, BranchStatus.RUNNING}: |
592 | 584 | # Exit here! Still have tasks that can make progress, don't suspend. |
593 | 585 | return SuspendResult.do_not_suspend() |
594 | 586 | if exe_state.status is BranchStatus.SUSPENDED_WITH_TIMEOUT: |
@@ -692,7 +684,6 @@ def _execute_item_in_child_context( |
692 | 684 | executable: Executable[CallableType], |
693 | 685 | ) -> ResultType: |
694 | 686 | """Execute a single item in a child context.""" |
695 | | - from aws_durable_execution_sdk_python.config import ChildConfig |
696 | 687 |
|
697 | 688 | def execute_in_child_context(child_context: DurableContext) -> ResultType: |
698 | 689 | return self.execute_item(child_context, executable) |
|
0 commit comments