relib 1.3.6__tar.gz → 1.3.7__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.7}/PKG-INFO +1 -1
- {relib-1.3.6 → relib-1.3.7}/pyproject.toml +1 -1
- {relib-1.3.6 → relib-1.3.7}/relib/dict_utils.py +23 -2
- {relib-1.3.6 → relib-1.3.7}/relib/iter_utils.py +1 -2
- {relib-1.3.6 → relib-1.3.7}/uv.lock +1 -1
- {relib-1.3.6 → relib-1.3.7}/.gitignore +0 -0
- {relib-1.3.6 → relib-1.3.7}/.python-version +0 -0
- {relib-1.3.6 → relib-1.3.7}/LICENSE +0 -0
- {relib-1.3.6 → relib-1.3.7}/README.md +0 -0
- {relib-1.3.6 → relib-1.3.7}/relib/__init__.py +0 -0
- {relib-1.3.6 → relib-1.3.7}/relib/io_utils.py +0 -0
- {relib-1.3.6 → relib-1.3.7}/relib/processing_utils.py +0 -0
- {relib-1.3.6 → relib-1.3.7}/relib/runtime_tools.py +0 -0
- {relib-1.3.6 → relib-1.3.7}/relib/type_utils.py +0 -0
- {relib-1.3.6 → relib-1.3.7}/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
|
|
@@ -37,9 +40,27 @@ def dict_by(keys: Iterable[K], values: Iterable[T]) -> dict[K, T]:
|
|
37
40
|
def tuple_by(d: dict[K, T], keys: Iterable[K]) -> tuple[T, ...]:
|
38
41
|
return tuple(d[key] for key in keys)
|
39
42
|
|
40
|
-
def map_dict(fn: Callable[[T],
|
43
|
+
def map_dict(fn: Callable[[T], T], d: dict[K, T]) -> dict[K, T]:
|
41
44
|
return {key: fn(value) for key, value in d.items()}
|
42
45
|
|
46
|
+
@overload
|
47
|
+
def remap(d: dict[K1, T1]) -> dict[K1, T1]: ...
|
48
|
+
@overload
|
49
|
+
def remap(d: dict[K1, T1], *, keys: dict[K1, K2] = {}) -> dict[K2, T1]: ...
|
50
|
+
@overload
|
51
|
+
def remap(d: dict[K1, T1], *, values: dict[T1, T2] = {}) -> dict[K1, T2]: ...
|
52
|
+
@overload
|
53
|
+
def remap(d: dict[K1, T1], *, keys: dict[K1, K2], values: dict[T1, T2]) -> dict[K2, T2]: ...
|
54
|
+
def remap(d: dict, *, keys=sentinel, values=sentinel) -> dict:
|
55
|
+
match (keys, values):
|
56
|
+
case (dict(), dict()):
|
57
|
+
return {keys[key]: values[value] for key, value in d.items()}
|
58
|
+
case (dict(), _):
|
59
|
+
return {keys[key]: value for key, value in d.items()}
|
60
|
+
case (_, dict()):
|
61
|
+
return {key: values[value] for key, value in d.items()}
|
62
|
+
return d
|
63
|
+
|
43
64
|
def key_of(dicts: Iterable[dict[T, U]], key: T) -> list[U]:
|
44
65
|
return [d[key] for d in dicts]
|
45
66
|
|
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
|