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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: relib
3
- Version: 1.3.6
3
+ Version: 1.3.7
4
4
  Project-URL: Repository, https://github.com/Reddan/relib.git
5
5
  Author: Hampus Hallman
6
6
  License: Copyright 2018-2025 Hampus Hallman
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "relib"
3
- version = "1.3.6"
3
+ version = "1.3.7"
4
4
  requires-python = ">=3.10"
5
5
  dependencies = []
6
6
  authors = [
@@ -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], U], d: dict[K, T]) -> dict[K, U]:
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
 
@@ -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",
@@ -161,7 +161,7 @@ wheels = [
161
161
 
162
162
  [[package]]
163
163
  name = "relib"
164
- version = "1.3.6"
164
+ version = "1.3.7"
165
165
  source = { editable = "." }
166
166
 
167
167
  [package.dev-dependencies]
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