Skip to content

Commit 992b4f4

Browse files
committed
make py39 compatible,
Signed-off-by: Filinto Duran <[email protected]>
1 parent e49c6dd commit 992b4f4

File tree

14 files changed

+113
-105
lines changed

14 files changed

+113
-105
lines changed

dev-requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
pytest-asyncio>=0.23
22
pytest
33
pytest-cov
4-
autopep8
54
grpcio>=1.74.0
6-
protobuf>=6.31.1
5+
protobuf>=6.31.1 # TODO: move to pyproject.toml when tox v4 is used

durabletask/aio/awaitables.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Any,
1818
Awaitable,
1919
Callable,
20+
Dict,
2021
Generator,
2122
Iterable,
2223
List,
@@ -80,8 +81,8 @@ def __init__(
8081
*,
8182
input: Any = None,
8283
retry_policy: Any = None,
83-
app_id: str | None = None,
84-
metadata: dict[str, str] | None = None,
84+
app_id: Optional[str] = None,
85+
metadata: Optional[Dict[str, str]] = None,
8586
):
8687
"""
8788
Initialize an activity awaitable.
@@ -115,7 +116,7 @@ def _to_task(self) -> task.Task[Any]:
115116
if (supports_metadata and self._metadata is not None) or (
116117
supports_app_id and self._app_id is not None
117118
):
118-
kwargs: dict[str, Any] = {'input': self._input}
119+
kwargs: Dict[str, Any] = {'input': self._input}
119120
if supports_metadata and self._metadata is not None:
120121
kwargs['metadata'] = self._metadata
121122
if supports_app_id and self._app_id is not None:
@@ -129,7 +130,7 @@ def _to_task(self) -> task.Task[Any]:
129130
if (supports_metadata and self._metadata is not None) or (
130131
supports_app_id and self._app_id is not None
131132
):
132-
kwargs2: dict[str, Any] = {'input': self._input, 'retry_policy': self._retry_policy}
133+
kwargs2: Dict[str, Any] = {'input': self._input, 'retry_policy': self._retry_policy}
133134
if supports_metadata and self._metadata is not None:
134135
kwargs2['metadata'] = self._metadata
135136
if supports_app_id and self._app_id is not None:
@@ -173,8 +174,8 @@ def __init__(
173174
input: Any = None,
174175
instance_id: Optional[str] = None,
175176
retry_policy: Any = None,
176-
app_id: str | None = None,
177-
metadata: dict[str, str] | None = None,
177+
app_id: Optional[str] = None,
178+
metadata: Optional[Dict[str, str]] = None,
178179
):
179180
"""
180181
Initialize a sub-orchestrator awaitable.
@@ -211,7 +212,7 @@ def _to_task(self) -> task.Task[Any]:
211212
if (supports_metadata and self._metadata is not None) or (
212213
supports_app_id and self._app_id is not None
213214
):
214-
kwargs: dict[str, Any] = {'input': self._input, 'instance_id': self._instance_id}
215+
kwargs: Dict[str, Any] = {'input': self._input, 'instance_id': self._instance_id}
215216
if supports_metadata and self._metadata is not None:
216217
kwargs['metadata'] = self._metadata
217218
if supports_app_id and self._app_id is not None:
@@ -236,7 +237,7 @@ def _to_task(self) -> task.Task[Any]:
236237
if (supports_metadata and self._metadata is not None) or (
237238
supports_app_id and self._app_id is not None
238239
):
239-
kwargs2: dict[str, Any] = {
240+
kwargs2: Dict[str, Any] = {
240241
'input': self._input,
241242
'instance_id': self._instance_id,
242243
'retry_policy': self._retry_policy,

durabletask/aio/compatibility.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from __future__ import annotations
1212

1313
from datetime import datetime, timedelta
14-
from typing import Any, Optional, Protocol, Union, runtime_checkable
14+
from typing import Any, Dict, Optional, Protocol, Union, runtime_checkable
1515

1616
from durabletask import task
1717

@@ -92,7 +92,7 @@ def call_activity(
9292
*,
9393
input: Optional[Any] = None,
9494
retry_policy: Optional[task.RetryPolicy] = None,
95-
metadata: Optional[dict[str, str]] = None,
95+
metadata: Optional[Dict[str, str]] = None,
9696
) -> Any:
9797
"""Schedule an activity for execution."""
9898
...
@@ -104,7 +104,7 @@ def call_sub_orchestrator(
104104
input: Optional[Any] = None,
105105
instance_id: Optional[str] = None,
106106
retry_policy: Optional[task.RetryPolicy] = None,
107-
metadata: Optional[dict[str, str]] = None,
107+
metadata: Optional[Dict[str, str]] = None,
108108
) -> Any:
109109
"""Schedule sub-orchestrator function for execution."""
110110
...

durabletask/aio/context.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def __init__(self, base_ctx: dt_task.OrchestrationContext):
9898
self._workflow_name: Optional[str] = None
9999
self._current_step: Optional[str] = None
100100
# Set by sandbox when active
101-
self._sandbox_originals: Optional[dict[str, Any]] = None
101+
self._sandbox_originals: Optional[Dict[str, Any]] = None
102102
self._sandbox_mode: Optional[str] = None
103103

104104
# Performance optimization: Check if detection should be globally disabled
@@ -236,7 +236,7 @@ def activity(
236236
input: Any = None,
237237
retry_policy: Any = None,
238238
app_id: Optional[str] = None,
239-
metadata: dict[str, str] | None = None,
239+
metadata: Optional[Dict[str, str]] = None,
240240
) -> ActivityAwaitable[Any]:
241241
"""
242242
Create an awaitable for calling an activity function.
@@ -267,7 +267,7 @@ def call_activity(
267267
input: Any = None,
268268
retry_policy: Any = None,
269269
app_id: Optional[str] = None,
270-
metadata: dict[str, str] | None = None,
270+
metadata: Optional[Dict[str, str]] = None,
271271
) -> ActivityAwaitable[Any]:
272272
"""Alias for activity() method for API compatibility."""
273273
return self.activity(
@@ -287,7 +287,7 @@ def sub_orchestrator(
287287
instance_id: Optional[str] = None,
288288
retry_policy: Any = None,
289289
app_id: Optional[str] = None,
290-
metadata: dict[str, str] | None = None,
290+
metadata: Optional[Dict[str, str]] = None,
291291
) -> SubOrchestratorAwaitable[Any]:
292292
"""
293293
Create an awaitable for calling a sub-orchestrator.
@@ -324,7 +324,7 @@ def call_sub_orchestrator(
324324
instance_id: Optional[str] = None,
325325
retry_policy: Any = None,
326326
app_id: Optional[str] = None,
327-
metadata: dict[str, str] | None = None,
327+
metadata: Optional[Dict[str, str]] = None,
328328
) -> SubOrchestratorAwaitable[Any]:
329329
"""Call a sub-orchestrator workflow (durabletask naming convention)."""
330330
return self.sub_orchestrator(
@@ -472,7 +472,7 @@ def continue_as_new(self, input_data: Any = None, *, save_events: bool = False)
472472
self._base_ctx.continue_as_new(input_data, save_events=save_events)
473473

474474
# Metadata and header methods
475-
def set_metadata(self, metadata: dict[str, str]) -> None:
475+
def set_metadata(self, metadata: Dict[str, str]) -> None:
476476
"""
477477
Set metadata for the workflow instance.
478478
@@ -483,7 +483,7 @@ def set_metadata(self, metadata: dict[str, str]) -> None:
483483
self._base_ctx.set_metadata(metadata)
484484
self._log_operation('set_metadata', {'metadata': metadata})
485485

486-
def get_metadata(self) -> Optional[dict[str, str]]:
486+
def get_metadata(self) -> Optional[Dict[str, str]]:
487487
"""
488488
Get metadata for the workflow instance.
489489
@@ -493,10 +493,10 @@ def get_metadata(self) -> Optional[dict[str, str]]:
493493
if hasattr(self._base_ctx, 'get_metadata'):
494494
val: Any = self._base_ctx.get_metadata()
495495
if isinstance(val, dict):
496-
return cast(dict[str, str], val)
496+
return cast(Dict[str, str], val)
497497
return None
498498

499-
def set_headers(self, headers: dict[str, str]) -> None:
499+
def set_headers(self, headers: Dict[str, str]) -> None:
500500
"""
501501
Set headers for the workflow instance (alias for set_metadata).
502502
@@ -505,7 +505,7 @@ def set_headers(self, headers: dict[str, str]) -> None:
505505
"""
506506
self.set_metadata(headers)
507507

508-
def get_headers(self) -> Optional[dict[str, str]]:
508+
def get_headers(self) -> Optional[Dict[str, str]]:
509509
"""
510510
Get headers for the workflow instance (alias for get_metadata).
511511

durabletask/aio/sandbox.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from datetime import timedelta
2121
from enum import Enum
2222
from types import FrameType
23-
from typing import Any, Callable, Optional, Union, cast
23+
from typing import Any, Callable, Dict, Optional, Set, Type, Union, cast
2424

2525
from durabletask.deterministic import deterministic_random, deterministic_uuid4
2626

@@ -38,17 +38,17 @@ class SandboxMode(str, Enum):
3838
STRICT = 'strict'
3939

4040

41-
def _as_mode_str(mode: str | SandboxMode) -> str:
41+
def _as_mode_str(mode: Union[str, SandboxMode]) -> str:
4242
return mode.value if isinstance(mode, SandboxMode) else mode
4343

4444

4545
class _NonDeterminismDetector:
4646
"""Detects and warns about non-deterministic function calls in workflows."""
4747

48-
def __init__(self, async_ctx: Any, mode: str | SandboxMode):
48+
def __init__(self, async_ctx: Any, mode: Union[str, SandboxMode]):
4949
self.async_ctx = async_ctx
5050
self.mode = _as_mode_str(mode)
51-
self.detected_calls: set[str] = set()
51+
self.detected_calls: Set[str] = set()
5252
self.original_trace_func: Optional[Callable[[FrameType, str, Any], Any]] = None
5353
self._restore_trace_func: Optional[Callable[[FrameType, str, Any], Any]] = None
5454
self._active_trace_func: Optional[Callable[[FrameType, str, Any], Any]] = None
@@ -74,7 +74,7 @@ def __enter__(self) -> '_NonDeterminismDetector':
7474

7575
def __exit__(
7676
self,
77-
exc_type: Optional[type[BaseException]],
77+
exc_type: Optional[Type[BaseException]],
7878
exc_val: Optional[BaseException],
7979
exc_tb: Optional[Any],
8080
) -> None:
@@ -272,11 +272,11 @@ def _get_deterministic_alternative(self, function_name: str) -> str:
272272
class _Sandbox(ContextDecorator):
273273
"""Context manager for sandboxing workflow execution."""
274274

275-
def __init__(self, async_ctx: Any, mode: str | SandboxMode):
275+
def __init__(self, async_ctx: Any, mode: Union[str, SandboxMode]):
276276
self.async_ctx = async_ctx
277277
self.mode = _as_mode_str(mode)
278-
self.originals: dict[str, Any] = {}
279-
self.detector: _NonDeterminismDetector | None = None
278+
self.originals: Dict[str, Any] = {}
279+
self.detector: Optional[_NonDeterminismDetector] = None
280280

281281
def __enter__(self) -> '_Sandbox':
282282
if self.mode == 'off':
@@ -305,7 +305,7 @@ def __enter__(self) -> '_Sandbox':
305305

306306
def __exit__(
307307
self,
308-
exc_type: Optional[type[BaseException]],
308+
exc_type: Optional[Type[BaseException]],
309309
exc_val: Optional[BaseException],
310310
exc_tb: Optional[Any],
311311
) -> None:
@@ -492,7 +492,7 @@ def __init__(self, factory: Callable[[], Any]) -> None:
492492
self._factory = factory
493493
self._done = False
494494
self._res: Any = None
495-
self._exc: BaseException | None = None
495+
self._exc: Optional[BaseException] = None
496496

497497
def __await__(self) -> Any:
498498
if self._done:
@@ -717,7 +717,7 @@ def _restore_originals(self) -> None:
717717

718718

719719
@contextlib.contextmanager
720-
def sandbox_scope(async_ctx: Any, mode: str | SandboxMode) -> Any:
720+
def sandbox_scope(async_ctx: Any, mode: Union[str, SandboxMode]) -> Any:
721721
"""
722722
Create a sandbox context for deterministic workflow execution.
723723

durabletask/deterministic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import uuid
1818
from dataclasses import dataclass
1919
from datetime import datetime
20-
from typing import Protocol, Sequence, TypeVar, runtime_checkable
20+
from typing import Optional, Protocol, Sequence, TypeVar, runtime_checkable
2121

2222

2323
@dataclass
@@ -105,7 +105,7 @@ def new_guid(self) -> uuid.UUID:
105105
"""Alias for uuid4 for API parity with other SDKs."""
106106
return self.uuid4()
107107

108-
def random_string(self, length: int, *, alphabet: str | None = None) -> str:
108+
def random_string(self, length: int, *, alphabet: Optional[str] = None) -> str:
109109
"""Return a deterministically generated random string of the given length."""
110110
if length < 0:
111111
raise ValueError('length must be non-negative')

durabletask/internal/shared.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import logging
77
import os
88
from types import SimpleNamespace
9-
from typing import Any, Iterable, Optional, Sequence, Union
9+
from typing import Any, Dict, Iterable, Optional, Sequence, Union
1010

1111
import grpc
1212

@@ -274,7 +274,7 @@ class InternalJSONDecoder(json.JSONDecoder):
274274
def __init__(self, *args, **kwargs):
275275
super().__init__(object_hook=self.dict_to_object, *args, **kwargs)
276276

277-
def dict_to_object(self, d: dict[str, Any]):
277+
def dict_to_object(self, d: Dict[str, Any]):
278278
# If the object was serialized by the InternalJSONEncoder, deserialize it as a SimpleNamespace
279279
if d.pop(AUTO_SERIALIZED, False):
280280
return SimpleNamespace(**d)

durabletask/worker.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from datetime import datetime, timedelta
1111
from threading import Event, Thread
1212
from types import GeneratorType
13-
from typing import Any, Callable, Generator, Optional, Sequence, TypeVar, Union
13+
from typing import Any, Callable, Dict, Generator, Optional, Sequence, TypeVar, Union
1414

1515
import grpc
1616
from google.protobuf import empty_pb2
@@ -74,8 +74,8 @@ def __init__(
7474

7575

7676
class _Registry:
77-
orchestrators: dict[str, task.Orchestrator]
78-
activities: dict[str, task.Activity]
77+
orchestrators: Dict[str, task.Orchestrator]
78+
activities: Dict[str, task.Activity]
7979

8080
def __init__(self):
8181
self.orchestrators = {}
@@ -808,15 +808,15 @@ def __init__(self, instance_id: str):
808808
self._is_suspended = False
809809
self._is_complete = False
810810
self._result = None
811-
self._pending_actions: dict[int, pb.OrchestratorAction] = {}
812-
self._pending_tasks: dict[int, task.CompletableTask] = {}
811+
self._pending_actions: Dict[int, pb.OrchestratorAction] = {}
812+
self._pending_tasks: Dict[int, task.CompletableTask] = {}
813813
self._sequence_number = 0
814814
self._current_utc_datetime = datetime(1000, 1, 1)
815815
self._instance_id = instance_id
816816
self._app_id = None
817817
self._completion_status: Optional[pb.OrchestrationStatus] = None
818-
self._received_events: dict[str, list[Any]] = {}
819-
self._pending_events: dict[str, list[task.CompletableTask]] = {}
818+
self._received_events: Dict[str, list[Any]] = {}
819+
self._pending_events: Dict[str, list[task.CompletableTask]] = {}
820820
self._new_input: Optional[Any] = None
821821
self._save_events = False
822822
self._encoded_custom_status: Optional[str] = None
@@ -1757,7 +1757,7 @@ def _get_new_event_summary(new_events: Sequence[pb.HistoryEvent]) -> str:
17571757
elif len(new_events) == 1:
17581758
return f'[{new_events[0].WhichOneof("eventType")}]'
17591759
else:
1760-
counts: dict[str, int] = {}
1760+
counts: Dict[str, int] = {}
17611761
for event in new_events:
17621762
event_type = event.WhichOneof('eventType')
17631763
counts[event_type] = counts.get(event_type, 0) + 1
@@ -1771,7 +1771,7 @@ def _get_action_summary(new_actions: Sequence[pb.OrchestratorAction]) -> str:
17711771
elif len(new_actions) == 1:
17721772
return f'[{new_actions[0].WhichOneof("orchestratorActionType")}]'
17731773
else:
1774-
counts: dict[str, int] = {}
1774+
counts: Dict[str, int] = {}
17751775
for action in new_actions:
17761776
action_type = action.WhichOneof('orchestratorActionType')
17771777
counts[action_type] = counts.get(action_type, 0) + 1

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+
# pyproject.toml has the dependencies for this project

0 commit comments

Comments
 (0)