relib 1.3.6__tar.gz → 1.3.8__tar.gz
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-1.3.6 → relib-1.3.8}/PKG-INFO +1 -1
- {relib-1.3.6 → relib-1.3.8}/pyproject.toml +1 -1
- {relib-1.3.6 → relib-1.3.8}/relib/dict_utils.py +28 -4
- {relib-1.3.6 → relib-1.3.8}/relib/iter_utils.py +10 -3
- {relib-1.3.6 → relib-1.3.8}/uv.lock +1 -1
- {relib-1.3.6 → relib-1.3.8}/.gitignore +0 -0
- {relib-1.3.6 → relib-1.3.8}/.python-version +0 -0
- {relib-1.3.6 → relib-1.3.8}/LICENSE +0 -0
- {relib-1.3.6 → relib-1.3.8}/README.md +0 -0
- {relib-1.3.6 → relib-1.3.8}/relib/__init__.py +0 -0
- {relib-1.3.6 → relib-1.3.8}/relib/io_utils.py +0 -0
- {relib-1.3.6 → relib-1.3.8}/relib/processing_utils.py +0 -0
- {relib-1.3.6 → relib-1.3.8}/relib/runtime_tools.py +0 -0
- {relib-1.3.6 → relib-1.3.8}/relib/type_utils.py +0 -0
- {relib-1.3.6 → relib-1.3.8}/relib/types.py +0 -0
@@ -1,6 +1,8 @@
|
|
1
1
|
from typing import Any, Callable, Iterable, overload
|
2
2
|
from .type_utils import as_any
|
3
|
-
from .types import K1, K2, K3, K4, K5, K6, K, T, U
|
3
|
+
from .types import K1, K2, K3, K4, K5, K6, T1, T2, K, T, U
|
4
|
+
|
5
|
+
sentinel = object()
|
4
6
|
|
5
7
|
__all__ = [
|
6
8
|
"deep_dict_pairs", "deepen_dict", "dict_by", "dict_firsts",
|
@@ -10,6 +12,7 @@ __all__ = [
|
|
10
12
|
"map_dict", "merge_dicts",
|
11
13
|
"omit",
|
12
14
|
"pick",
|
15
|
+
"remap",
|
13
16
|
"tuple_by",
|
14
17
|
]
|
15
18
|
|
@@ -21,11 +24,14 @@ def merge_dicts(*dicts: dict[K, T]) -> dict[K, T]:
|
|
21
24
|
result |= d
|
22
25
|
return result
|
23
26
|
|
24
|
-
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]:
|
25
28
|
if keys:
|
26
29
|
d = dict(d)
|
27
30
|
for key in keys:
|
28
|
-
|
31
|
+
try:
|
32
|
+
del d[key]
|
33
|
+
except KeyError if optional else ():
|
34
|
+
pass
|
29
35
|
return d
|
30
36
|
|
31
37
|
def pick(d: dict[K, T], keys: Iterable[K]) -> dict[K, T]:
|
@@ -37,9 +43,27 @@ def dict_by(keys: Iterable[K], values: Iterable[T]) -> dict[K, T]:
|
|
37
43
|
def tuple_by(d: dict[K, T], keys: Iterable[K]) -> tuple[T, ...]:
|
38
44
|
return tuple(d[key] for key in keys)
|
39
45
|
|
40
|
-
def map_dict(fn: Callable[[T],
|
46
|
+
def map_dict(fn: Callable[[T], T], d: dict[K, T]) -> dict[K, T]:
|
41
47
|
return {key: fn(value) for key, value in d.items()}
|
42
48
|
|
49
|
+
@overload
|
50
|
+
def remap(d: dict[K1, T1]) -> dict[K1, T1]: ...
|
51
|
+
@overload
|
52
|
+
def remap(d: dict[K1, T1], *, keys: dict[K1, K2] = {}) -> dict[K2, T1]: ...
|
53
|
+
@overload
|
54
|
+
def remap(d: dict[K1, T1], *, values: dict[T1, T2] = {}) -> dict[K1, T2]: ...
|
55
|
+
@overload
|
56
|
+
def remap(d: dict[K1, T1], *, keys: dict[K1, K2], values: dict[T1, T2]) -> dict[K2, T2]: ...
|
57
|
+
def remap(d: dict, *, keys=sentinel, values=sentinel) -> dict:
|
58
|
+
match (keys, values):
|
59
|
+
case (dict(), dict()):
|
60
|
+
return {keys[key]: values[value] for key, value in d.items()}
|
61
|
+
case (dict(), _):
|
62
|
+
return {keys[key]: value for key, value in d.items()}
|
63
|
+
case (_, dict()):
|
64
|
+
return {key: values[value] for key, value in d.items()}
|
65
|
+
return d
|
66
|
+
|
43
67
|
def key_of(dicts: Iterable[dict[T, U]], key: T) -> list[U]:
|
44
68
|
return [d[key] for d in dicts]
|
45
69
|
|
@@ -6,8 +6,7 @@ from .dict_utils import dict_firsts
|
|
6
6
|
from .types import T1, T2, T3, T4, T5, T, U
|
7
7
|
|
8
8
|
__all__ = [
|
9
|
-
"as_list",
|
10
|
-
"at",
|
9
|
+
"as_list", "at",
|
11
10
|
"chunked",
|
12
11
|
"distinct_by", "distinct", "drop_none",
|
13
12
|
"first", "flatten",
|
@@ -15,7 +14,7 @@ __all__ = [
|
|
15
14
|
"list_split",
|
16
15
|
"move_value",
|
17
16
|
"partition",
|
18
|
-
"reversed_enumerate",
|
17
|
+
"range_of", "reversed_enumerate",
|
19
18
|
"seekable", "sort_by",
|
20
19
|
"transpose",
|
21
20
|
]
|
@@ -74,6 +73,9 @@ def partition(iterable: Iterable[tuple[bool, T]]) -> tuple[list[T], list[T]]:
|
|
74
73
|
false_values.append(value)
|
75
74
|
return true_values, false_values
|
76
75
|
|
76
|
+
def range_of(values: Sequence) -> range:
|
77
|
+
return range(len(values))
|
78
|
+
|
77
79
|
class seekable(Generic[T]):
|
78
80
|
def __init__(self, iterable: Iterable[T]):
|
79
81
|
self.index = 0
|
@@ -124,6 +126,11 @@ class seekable(Generic[T]):
|
|
124
126
|
with self.freeze():
|
125
127
|
return list(islice(self, count))
|
126
128
|
|
129
|
+
def forgetful(self) -> Iterable[T]:
|
130
|
+
for value in self:
|
131
|
+
self.clear()
|
132
|
+
yield value
|
133
|
+
|
127
134
|
@overload
|
128
135
|
def chunked(values: Iterable[T], *, num_chunks: int, chunk_size=None) -> list[list[T]]: ...
|
129
136
|
@overload
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|