relib 1.3.7__py3-none-any.whl → 1.3.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- relib/dict_utils.py +5 -2
- relib/iter_utils.py +19 -4
- {relib-1.3.7.dist-info → relib-1.3.9.dist-info}/METADATA +1 -1
- {relib-1.3.7.dist-info → relib-1.3.9.dist-info}/RECORD +6 -6
- {relib-1.3.7.dist-info → relib-1.3.9.dist-info}/WHEEL +0 -0
- {relib-1.3.7.dist-info → relib-1.3.9.dist-info}/licenses/LICENSE +0 -0
relib/dict_utils.py
CHANGED
@@ -24,11 +24,14 @@ def merge_dicts(*dicts: dict[K, T]) -> dict[K, T]:
|
|
24
24
|
result |= d
|
25
25
|
return result
|
26
26
|
|
27
|
-
def omit(d: dict[K, T], keys: Iterable[K]) -> dict[K, T]:
|
27
|
+
def omit(d: dict[K, T], keys: Iterable[K], optional=False) -> dict[K, T]:
|
28
28
|
if keys:
|
29
29
|
d = dict(d)
|
30
30
|
for key in keys:
|
31
|
-
|
31
|
+
try:
|
32
|
+
del d[key]
|
33
|
+
except KeyError if optional else ():
|
34
|
+
pass
|
32
35
|
return d
|
33
36
|
|
34
37
|
def pick(d: dict[K, T], keys: Iterable[K]) -> dict[K, T]:
|
relib/iter_utils.py
CHANGED
@@ -14,7 +14,7 @@ __all__ = [
|
|
14
14
|
"list_split",
|
15
15
|
"move_value",
|
16
16
|
"partition",
|
17
|
-
"reversed_enumerate",
|
17
|
+
"range_of", "reversed_enumerate",
|
18
18
|
"seekable", "sort_by",
|
19
19
|
"transpose",
|
20
20
|
]
|
@@ -73,6 +73,9 @@ def partition(iterable: Iterable[tuple[bool, T]]) -> tuple[list[T], list[T]]:
|
|
73
73
|
false_values.append(value)
|
74
74
|
return true_values, false_values
|
75
75
|
|
76
|
+
def range_of(values: Sequence) -> range:
|
77
|
+
return range(len(values))
|
78
|
+
|
76
79
|
class seekable(Generic[T]):
|
77
80
|
def __init__(self, iterable: Iterable[T]):
|
78
81
|
self.index = 0
|
@@ -92,7 +95,7 @@ class seekable(Generic[T]):
|
|
92
95
|
return item
|
93
96
|
|
94
97
|
def __bool__(self):
|
95
|
-
return bool(self
|
98
|
+
return bool(self[:1])
|
96
99
|
|
97
100
|
def clear(self):
|
98
101
|
self.sink[:self.index] = []
|
@@ -119,9 +122,21 @@ class seekable(Generic[T]):
|
|
119
122
|
finally:
|
120
123
|
self.seek(initial_index)
|
121
124
|
|
122
|
-
|
125
|
+
@overload
|
126
|
+
def __getitem__(self, key: int) -> T: ...
|
127
|
+
@overload
|
128
|
+
def __getitem__(self, key: slice[int | None]) -> list[T]: ...
|
129
|
+
def __getitem__(self, key: int | slice[int | None]):
|
123
130
|
with self.freeze():
|
124
|
-
|
131
|
+
if isinstance(key, slice):
|
132
|
+
return list(islice(self, key.start, key.stop, key.step))
|
133
|
+
elif isinstance(key, int):
|
134
|
+
return self[:key][key - 1]
|
135
|
+
|
136
|
+
def consume(self) -> Iterable[T]:
|
137
|
+
for value in self:
|
138
|
+
self.clear()
|
139
|
+
yield value
|
125
140
|
|
126
141
|
@overload
|
127
142
|
def chunked(values: Iterable[T], *, num_chunks: int, chunk_size=None) -> list[list[T]]: ...
|
@@ -1,12 +1,12 @@
|
|
1
1
|
relib/__init__.py,sha256=WerjUaM_sNvudjXFudLRtXB7viZWEW1RSinkDjrh4nE,163
|
2
|
-
relib/dict_utils.py,sha256=
|
2
|
+
relib/dict_utils.py,sha256=ez8egTPvO05wVNWIyO-aJjtqaXUDYbzyw32M42q1D44,3677
|
3
3
|
relib/io_utils.py,sha256=cUyUFhrMCUDfkINhYo32QPaVGz3chqDO3ElymSCoWEg,1086
|
4
|
-
relib/iter_utils.py,sha256=
|
4
|
+
relib/iter_utils.py,sha256=l5LwIGX8QEMhV1ESTPLd6DVYNtX_EtaxMwewDkKYQM4,6193
|
5
5
|
relib/processing_utils.py,sha256=kFb4izrR8vec9BFWeGSb-TXR54bbA4X3dxAfIBZItuI,1911
|
6
6
|
relib/runtime_tools.py,sha256=6HpRXmAHHLq4bNRj6fSiaLQeHR2h3OdxFZxaB93fXhI,2979
|
7
7
|
relib/type_utils.py,sha256=68yEhEIBCIKfsIT1u647avHVA_JjVvDYSdtLD3nCrJs,338
|
8
8
|
relib/types.py,sha256=JzSGDl2L6tUWizGSsUpuyCKf-VKgtgfK_n21azSSMLM,288
|
9
|
-
relib-1.3.
|
10
|
-
relib-1.3.
|
11
|
-
relib-1.3.
|
12
|
-
relib-1.3.
|
9
|
+
relib-1.3.9.dist-info/METADATA,sha256=PDPyPnwAoBCQnWWQcEjpkGy8R4XSe-hwApHOC8bpOao,1295
|
10
|
+
relib-1.3.9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
11
|
+
relib-1.3.9.dist-info/licenses/LICENSE,sha256=9xVsdtv_-uSyY9Xl9yujwAPm4-mjcCLeVy-ljwXEWbo,1059
|
12
|
+
relib-1.3.9.dist-info/RECORD,,
|
File without changes
|
File without changes
|