Skip to content

Commit fd47983

Browse files
committed
chore: remove OrderedDict
Signed-off-by: Yves Bastide <yves@botify.com>
1 parent 1723c3e commit fd47983

File tree

3 files changed

+34
-45
lines changed

3 files changed

+34
-45
lines changed

simpleflow/local/executor.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import collections
43
import sys
54
import traceback
65
import uuid
@@ -27,8 +26,8 @@ def __init__(self, workflow_class, **kwargs):
2726
super().__init__(workflow_class)
2827
self.update_workflow_class()
2928
self.nb_activities = 0
30-
self.signals_sent = set()
31-
self._markers = collections.OrderedDict()
29+
self.signals_sent: set[str] = set()
30+
self._markers: dict[str, list[Marker]] = {}
3231

3332
self.wf_run_id = []
3433
self.wf_id = []
@@ -206,7 +205,7 @@ def continue_as_new(self, workflow: type[Workflow], *args, **kwargs):
206205
self.update_workflow_class()
207206
self.nb_activities = 0
208207
self.signals_sent = set()
209-
self._markers = collections.OrderedDict()
208+
self._markers = {}
210209

211210
self.wf_run_id = []
212211
self.wf_id = []

simpleflow/metrology.py

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import re
77
import time
88
from abc import ABC
9-
from collections import OrderedDict
109
from typing import Any
1110
from urllib.parse import quote_plus
1211

@@ -18,31 +17,29 @@
1817

1918

2019
class StepIO:
21-
def __init__(self):
20+
def __init__(self) -> None:
2221
self.bytes = 0
2322
self.records = 0
2423
self.sampled = False
2524

26-
def get_stats(self, time_total):
25+
def get_stats(self, time_total: float) -> dict[str, Any]:
2726
mb_s = None
2827
rec_s = None
2928
if self.bytes:
3029
mb_s = round(float(self.bytes) / (1024 * 1024) / time_total, 2)
3130
if self.records:
3231
rec_s = int(self.records / time_total)
33-
return OrderedDict(
34-
[
35-
("bytes", self.bytes),
36-
("records", self.records),
37-
("mb_s", mb_s),
38-
("rec_s", rec_s),
39-
("sampled", self.sampled),
40-
]
41-
)
32+
return {
33+
"bytes": self.bytes,
34+
"records": self.records,
35+
"mb_s": mb_s,
36+
"rec_s": rec_s,
37+
"sampled": self.sampled,
38+
}
4239

4340

4441
class Step:
45-
def __init__(self, name, task):
42+
def __init__(self, name: str, task: MetrologyTask) -> None:
4643
self.name = name
4744
self.task = task
4845
self.read = StepIO()
@@ -57,22 +54,17 @@ def done(self):
5754
self.time_total = self.time_finished - self.time_started
5855

5956
def get_stats(self):
60-
stats = OrderedDict(
61-
[
62-
("name", self.name),
63-
("metadata", self.metadata),
64-
("time_started", self.time_started),
65-
("time_finished", self.time_finished),
66-
("time_total", self.time_total),
67-
("read", self.read.get_stats(self.time_total)),
68-
("write", self.write.get_stats(self.time_total)),
69-
]
70-
)
71-
return stats
57+
stats = {
58+
"name": self.name,
59+
"metadata": self.metadata,
60+
"time_started": self.time_started,
61+
"time_finished": self.time_finished,
62+
"time_total": self.time_total,
63+
"read": self.read.get_stats(self.time_total),
64+
"write": self.write.get_stats(self.time_total),
65+
}
7266

73-
def mset_metadata(self, kvs):
74-
for k, v in kvs:
75-
self.metadata[k] = v
67+
return stats
7668

7769

7870
class StepExecution:
@@ -90,22 +82,22 @@ class MetrologyTask:
9082
context: dict[str, Any]
9183
steps: list[Step]
9284

93-
def can_upload(self):
85+
def can_upload(self) -> bool:
9486
if not hasattr(self, "context"):
9587
return False
9688
return all(c in self.context for c in ("workflow_id", "run_id", "activity_id"))
9789

9890
@property
9991
def metrology_path(self):
100-
path = []
92+
path: list[str] = []
10193
if settings.METROLOGY_PATH_PREFIX is not None:
10294
path.append(settings.METROLOGY_PATH_PREFIX)
10395
path.append(self.context["workflow_id"])
10496
path.append(quote_plus(self.context["run_id"]))
10597
path.append(f"activity.{self.context['activity_id']}.json")
10698
return str(os.path.join(*path))
10799

108-
def step(self, name):
100+
def step(self, name: str) -> StepExecution:
109101
"""
110102
To be called in a `with` execution
111103
Ex :

simpleflow/swf/mapper/models/base.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from collections import OrderedDict, namedtuple
3+
from collections import namedtuple
44

55
from simpleflow.swf.mapper.core import ConnectedSWFObject
66
from simpleflow.swf.mapper.exceptions import DoesNotExistError
@@ -13,15 +13,13 @@ class ModelDiff:
1313
1414
:param input: triples (tuples) storing in order: compared attribute name,
1515
local model attribute value, upstream model attribute value.
16-
:type input: *args
1716
1817
:param ignore_fields: list of fields to ignore when comparing local and upstream
19-
:type ignore_fields: list
2018
"""
2119

22-
def __init__(self, *input, ignore_fields: list[str] | None = None):
20+
def __init__(self, *input: tuple[str, str, str], ignore_fields: list[str] | None = None):
2321
self.ignore_fields = ignore_fields or []
24-
self.container: OrderedDict[str, tuple[str, str]] = self._process_input(input)
22+
self.container: dict[str, tuple[str, str]] = self._process_input(input)
2523

2624
def __contains__(self, attr):
2725
return attr in self.container
@@ -33,14 +31,14 @@ def __getitem__(self, index):
3331
attr, (local, upstream) = list(self.container.items())[index]
3432
return Difference(attr, local, upstream)
3533

36-
def _process_input(self, input):
37-
return OrderedDict(
38-
(attr, (local, upstream))
34+
def _process_input(self, input: tuple[tuple[str, str, str], ...]) -> dict[str, tuple[str, str]]:
35+
return {
36+
attr: (local, upstream)
3937
for attr, local, upstream in input
4038
if local != upstream and attr not in self.ignore_fields
41-
)
39+
}
4240

43-
def add_input(self, *input):
41+
def add_input(self, *input: tuple[str, str, str]):
4442
"""Adds input differing data into ModelDiff instance"""
4543
self.container.update(self._process_input(input))
4644

0 commit comments

Comments
 (0)