Skip to content

Commit 0dbccf1

Browse files
authored
Make codebase MyPy compliant (#293)
1 parent 670fb52 commit 0dbccf1

File tree

7 files changed

+25
-6
lines changed

7 files changed

+25
-6
lines changed

azure/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Base module for the Python Durable functions."""
22
from pkgutil import extend_path
3-
__path__ = extend_path(__path__, __name__)
3+
__path__ = extend_path(__path__, __name__) # type: ignore

azure/durable_functions/models/DurableOrchestrationClient.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,8 @@ async def wait_for_completion_or_create_check_status_response(
440440
lambda: self._create_http_response(200, status.to_json()),
441441
OrchestrationRuntimeStatus.Failed:
442442
lambda: self._create_http_response(500, status.to_json()),
443+
None:
444+
None
443445
}
444446

445447
result = switch_statement.get(status.runtime_status)
@@ -456,6 +458,7 @@ async def wait_for_completion_or_create_check_status_response(
456458
await sleep(sleep_time)
457459
else:
458460
return self.create_check_status_response(request, instance_id)
461+
return self.create_check_status_response(request, instance_id)
459462

460463
async def signal_entity(self, entityId: EntityId, operation_name: str,
461464
operation_input: Optional[Any] = None,
@@ -640,6 +643,7 @@ async def rewind(self,
640643

641644
response = await self._post_async_request(request_url, None)
642645
status: int = response[0]
646+
ex_msg: str = ""
643647
if status == 200 or status == 202:
644648
return
645649
elif status == 404:
@@ -648,6 +652,9 @@ async def rewind(self,
648652
elif status == 410:
649653
ex_msg = "The rewind operation is only supported on failed orchestration instances."
650654
raise Exception(ex_msg)
651-
else:
655+
elif isinstance(response[1], str):
652656
ex_msg = response[1]
653657
raise Exception(ex_msg)
658+
else:
659+
ex_msg = "Received unexpected payload from the durable-extension: " + str(response)
660+
raise Exception(ex_msg)

azure/durable_functions/models/history/HistoryEvent.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ def __init__(self, EventType: HistoryEventType, EventId: int, IsPlayed: bool, Ti
1414
self._is_played: bool = IsPlayed
1515
self._timestamp: datetime.datetime = dt_parse(Timestamp)
1616
self._is_processed: bool = False
17+
18+
self.Name = None
19+
self.InstanceId = None
20+
self.TaskScheduledId = None
21+
self.Reason = None
22+
self.Details = None
23+
self.Input = None
1724
if kwargs is not None:
1825
for key, value in kwargs.items():
1926
self.__setattr__(key, value)

azure/durable_functions/tasks/call_entity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def call_entity_task(
5151
event_raised = None
5252
if event_sent:
5353
event_input = None
54-
if hasattr(event_sent, "Input"):
54+
if hasattr(event_sent, "Input") and event_sent.Input is not None:
5555
event_input = RequestMessage.from_json(event_sent.Input)
5656
hist_type = HistoryEventType.EVENT_RAISED
5757
extra_constraints = {

azure/durable_functions/tasks/task_all.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def task_all(tasks: List[Task]):
5959

6060
# Incomplete TaskSets do not have results or end-time
6161
if not is_completed:
62-
results = None
62+
results = []
6363
end_time = None
6464

6565
# Construct TaskSet

azure/durable_functions/tasks/task_utilities.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,18 @@ def gen_err_message(counter: int, mid_message: str, found: str, expected: str) -
304304
# TODO: The HistoryEvent does not necessarily have a name or an instance_id
305305
# We should create sub-classes of these types like JS does, to ensure their
306306
# precense.
307+
308+
if event.Name is None:
309+
raise ValueError("History Event for suborchestration found with no {Name} field")
310+
event_name: str = event.Name
307311
err_message: str = ""
308312
if not(event.Name == name):
309313
mid_message = "a function name of {} instead of the provided function name of {}."
310-
err_message = gen_err_message(counter, mid_message, event.Name, name)
314+
err_message = gen_err_message(counter, mid_message, event_name, name)
311315
raise ValueError(err_message)
312316
if instance_id and not(event.InstanceId == instance_id):
313317
mid_message = "an instance id of {} instead of the provided instance id of {}."
314-
err_message = gen_err_message(counter, mid_message, event.Name, name)
318+
err_message = gen_err_message(counter, mid_message, event_name, name)
315319
raise ValueError(err_message)
316320

317321
return event

noxfile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ def lint(session):
1616

1717
@nox.session(python=["3.7", "3.8"])
1818
def typecheck(session):
19+
session.install("-r", "requirements.txt")
1920
session.install("mypy")
2021
session.run("mypy", "./azure/")

0 commit comments

Comments
 (0)