1
1
from __future__ import annotations
2
2
3
- from typing import Any , Callable , Iterator , List , NamedTuple , Tuple , Optional , TypeVar , FrozenSet , TYPE_CHECKING , Hashable , Union
3
+ from typing import (
4
+ Any ,
5
+ Callable ,
6
+ Iterator ,
7
+ List ,
8
+ NamedTuple ,
9
+ Tuple ,
10
+ Optional ,
11
+ TypeVar ,
12
+ FrozenSet ,
13
+ TYPE_CHECKING ,
14
+ Hashable ,
15
+ Union ,
16
+ )
4
17
5
18
import h3
6
19
import immutables
11
24
from _typeshed import SupportsRichComparison
12
25
13
26
14
-
15
27
class EntityUpdateResult (NamedTuple ):
16
28
entities : Optional [immutables .Map [EntityId , Entity ]] = None
17
29
locations : Optional [immutables .Map [GeoId , FrozenSet [EntityId ]]] = None
@@ -23,9 +35,11 @@ class DictOps:
23
35
V = TypeVar ("V" )
24
36
25
37
@classmethod
26
- def iterate_vals (cls , xs : immutables .Map [K , V ], key : Optional [Callable [[V ], SupportsRichComparison ]]= None ) -> Tuple [V , ...]:
38
+ def iterate_vals (
39
+ cls , xs : immutables .Map [K , V ], key : Optional [Callable [[V ], SupportsRichComparison ]] = None
40
+ ) -> Tuple [V , ...]:
27
41
"""
28
- helper function for iterating on Maps in HIVE which sorts values by key unless a key function
42
+ helper function for iterating on Maps in HIVE which sorts values by key unless a key function
29
43
is provided. for all stateful Map collections that are being iterated on in HIVE, we need
30
44
to sort them _somehow_ to guarantee deterministic runs.
31
45
@@ -34,7 +48,7 @@ def iterate_vals(cls, xs: immutables.Map[K, V], key: Optional[Callable[[V], Supp
34
48
35
49
:param xs: collection to iterate values of
36
50
:type xs: immutables.Map[K, V]
37
- :return: values of xs, sorted by key
51
+ :return: values of xs, sorted by key
38
52
:rtype: Tuple[V, ...]
39
53
"""
40
54
# forcing ignore here after numerous attempts to set the bounds for K
@@ -47,17 +61,21 @@ def iterate_vals(cls, xs: immutables.Map[K, V], key: Optional[Callable[[V], Supp
47
61
else :
48
62
vs = sorted (xs .values (), key = key ) # type: ignore
49
63
return vs
50
-
64
+
51
65
@classmethod
52
- def iterate_items (cls , xs : immutables .Map [K , V ], key : Optional [Callable [[Tuple [K , V ]], SupportsRichComparison ]]= None ) -> List [Tuple [K , V ]]:
66
+ def iterate_items (
67
+ cls ,
68
+ xs : immutables .Map [K , V ],
69
+ key : Optional [Callable [[Tuple [K , V ]], SupportsRichComparison ]] = None ,
70
+ ) -> List [Tuple [K , V ]]:
53
71
"""
54
- helper function for iterating on Maps in HIVE which sorts values by key unless a key function
72
+ helper function for iterating on Maps in HIVE which sorts values by key unless a key function
55
73
is provided. for all stateful Map collections that are being iterated on in HIVE, we need
56
74
to sort them _somehow_ to guarantee deterministic runs.
57
75
58
76
:param xs: collection to iterate values of
59
77
:type xs: immutables.Map[K, V]
60
- :return: values of xs, sorted by key
78
+ :return: values of xs, sorted by key
61
79
:rtype: Tuple[V, ...]
62
80
"""
63
81
# forcing ignore here after numerous attempts to set the bounds for K
@@ -71,10 +89,10 @@ def iterate_items(cls, xs: immutables.Map[K, V], key: Optional[Callable[[Tuple[K
71
89
72
90
@classmethod
73
91
def iterate_sim_coll (
74
- cls ,
75
- collection : immutables .Map [K , V ],
76
- filter_function : Optional [Callable [[V ], bool ]] = None ,
77
- sort_key : Optional [Callable ] = None
92
+ cls ,
93
+ collection : immutables .Map [K , V ],
94
+ filter_function : Optional [Callable [[V ], bool ]] = None ,
95
+ sort_key : Optional [Callable ] = None ,
78
96
) -> Tuple [V , ...]:
79
97
"""
80
98
helper to iterate through a collection on the SimulationState with optional
@@ -89,14 +107,13 @@ def iterate_sim_coll(
89
107
:return: _description_
90
108
:rtype: Tuple[V, ...]
91
109
"""
92
-
93
- vals = DictOps .iterate_vals (collection , sort_key )
110
+
111
+ vals = DictOps .iterate_vals (collection , sort_key )
94
112
if filter_function :
95
113
return tuple (filter (filter_function , vals ))
96
114
else :
97
115
return vals
98
116
99
-
100
117
@classmethod
101
118
def add_to_dict (cls , xs : immutables .Map [K , V ], obj_id : K , obj : V ) -> immutables .Map [K , V ]:
102
119
"""
0 commit comments