relib 1.3.7__tar.gz → 1.3.9__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.7
3
+ Version: 1.3.9
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.7"
3
+ version = "1.3.9"
4
4
  requires-python = ">=3.10"
5
5
  dependencies = []
6
6
  authors = [
@@ -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
- del d[key]
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]:
@@ -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.lookahead(1))
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
- def lookahead(self, count: int) -> list[T]:
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
- return list(islice(self, count))
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]]: ...
@@ -161,7 +161,7 @@ wheels = [
161
161
 
162
162
  [[package]]
163
163
  name = "relib"
164
- version = "1.3.7"
164
+ version = "1.3.9"
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