checkpointer 2.14.8__tar.gz → 2.14.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.
Files changed (21) hide show
  1. {checkpointer-2.14.8 → checkpointer-2.14.9}/PKG-INFO +1 -1
  2. {checkpointer-2.14.8 → checkpointer-2.14.9}/checkpointer/checkpoint.py +13 -9
  3. {checkpointer-2.14.8 → checkpointer-2.14.9}/checkpointer/object_hash.py +3 -1
  4. {checkpointer-2.14.8 → checkpointer-2.14.9}/pyproject.toml +1 -1
  5. {checkpointer-2.14.8 → checkpointer-2.14.9}/uv.lock +1 -1
  6. {checkpointer-2.14.8 → checkpointer-2.14.9}/.gitignore +0 -0
  7. {checkpointer-2.14.8 → checkpointer-2.14.9}/.python-version +0 -0
  8. {checkpointer-2.14.8 → checkpointer-2.14.9}/ATTRIBUTION.md +0 -0
  9. {checkpointer-2.14.8 → checkpointer-2.14.9}/LICENSE +0 -0
  10. {checkpointer-2.14.8 → checkpointer-2.14.9}/README.md +0 -0
  11. {checkpointer-2.14.8 → checkpointer-2.14.9}/checkpointer/__init__.py +0 -0
  12. {checkpointer-2.14.8 → checkpointer-2.14.9}/checkpointer/fn_ident.py +0 -0
  13. {checkpointer-2.14.8 → checkpointer-2.14.9}/checkpointer/fn_string.py +0 -0
  14. {checkpointer-2.14.8 → checkpointer-2.14.9}/checkpointer/import_mappings.py +0 -0
  15. {checkpointer-2.14.8 → checkpointer-2.14.9}/checkpointer/print_checkpoint.py +0 -0
  16. {checkpointer-2.14.8 → checkpointer-2.14.9}/checkpointer/storages/__init__.py +0 -0
  17. {checkpointer-2.14.8 → checkpointer-2.14.9}/checkpointer/storages/memory_storage.py +0 -0
  18. {checkpointer-2.14.8 → checkpointer-2.14.9}/checkpointer/storages/pickle_storage.py +0 -0
  19. {checkpointer-2.14.8 → checkpointer-2.14.9}/checkpointer/storages/storage.py +0 -0
  20. {checkpointer-2.14.8 → checkpointer-2.14.9}/checkpointer/types.py +0 -0
  21. {checkpointer-2.14.8 → checkpointer-2.14.9}/checkpointer/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: checkpointer
3
- Version: 2.14.8
3
+ Version: 2.14.9
4
4
  Summary: checkpointer adds code-aware caching to Python functions, maintaining correctness and speeding up execution as your code changes.
5
5
  Project-URL: Repository, https://github.com/Reddan/checkpointer.git
6
6
  Author: Hampus Hallman
@@ -150,6 +150,8 @@ class CachedFunction(Generic[Fn]):
150
150
 
151
151
  @property
152
152
  def fn(self) -> Fn:
153
+ if self.bound:
154
+ return self.ident.fn.__get__(self.bound[0], self.bound[0].__class__) # type: ignore
153
155
  return self.ident.fn # type: ignore
154
156
 
155
157
  @cached_property
@@ -201,17 +203,16 @@ class CachedFunction(Generic[Fn]):
201
203
  def is_expired(self, call_hash: str) -> bool:
202
204
  return not self.storage.exists(call_hash) or self.storage.expired(call_hash)
203
205
 
204
- def _call(self: CachedFunction[Callable[P, R]], args: tuple, kw: dict, rerun=False, cached=False) -> R:
205
- full_args = self.bound + args
206
+ def _call(self: CachedFunction[Callable[P, R]], args: tuple, kw: dict, cached=True, rerun=False) -> R:
206
207
  params = self.ident.checkpointer
207
- if not params.when and not cached:
208
- return self.fn(*full_args, **kw)
208
+ if not cached:
209
+ return self.fn(*args, **kw)
209
210
  call_hash = self._get_call_hash(args, kw)
210
211
  call_id = f"{self.storage.fn_id()}/{call_hash}"
211
212
 
212
213
  if rerun or self.is_expired(call_hash):
213
214
  print_checkpoint(params.verbosity >= 1, "MEMORIZING", call_id, "blue")
214
- data = self.fn(*full_args, **kw)
215
+ data = self.fn(*args, **kw)
215
216
  if iscoroutine(data):
216
217
  return self._store_coroutine(call_hash, data)
217
218
  return self.storage.store(call_hash, data)
@@ -225,16 +226,19 @@ class CachedFunction(Generic[Fn]):
225
226
  except (EOFError, FileNotFoundError):
226
227
  pass
227
228
  print_checkpoint(params.verbosity >= 1, "CORRUPTED", call_id, "yellow")
228
- return self._call(args, kw, True, cached)
229
+ return self._call(args, kw, rerun=True)
229
230
 
230
231
  def __call__(self: CachedFunction[Callable[P, R]], *args: P.args, **kw: P.kwargs) -> R:
231
- return self._call(args, kw)
232
+ return self._call(args, kw, self.ident.checkpointer.when)
232
233
 
233
234
  def cached(self: CachedFunction[Callable[P, R]], *args: P.args, **kw: P.kwargs) -> R:
234
- return self._call(args, kw, False, True)
235
+ return self._call(args, kw, True)
236
+
237
+ def uncached(self: CachedFunction[Callable[P, R]], *args: P.args, **kw: P.kwargs) -> R:
238
+ return self._call(args, kw, False)
235
239
 
236
240
  def rerun(self: CachedFunction[Callable[P, R]], *args: P.args, **kw: P.kwargs) -> R:
237
- return self._call(args, kw, True, True)
241
+ return self._call(args, kw, rerun=True)
238
242
 
239
243
  def exists(self: CachedFunction[Callable[P, R]], *args: P.args, **kw: P.kwargs) -> bool:
240
244
  return self.storage.exists(self._get_call_hash(args, kw))
@@ -35,6 +35,8 @@ else:
35
35
  nc = nullcontext()
36
36
  stdlib = Path(sysconfig.get_paths()["stdlib"]).resolve()
37
37
 
38
+ Buffer = bytes | bytearray | memoryview
39
+
38
40
  def encode_type(t: type | FunctionType) -> str:
39
41
  return f"{t.__module__}:{t.__qualname__}"
40
42
 
@@ -69,7 +71,7 @@ class ObjectHash:
69
71
  def nested_hash(self, *objs: object) -> str:
70
72
  return ObjectHash(iter=objs, tolerable=self.tolerable.value).hexdigest()
71
73
 
72
- def write_bytes(self, *data: bytes, iter: Iterable[bytes] = ()) -> Self:
74
+ def write_bytes(self, *data: Buffer, iter: Iterable[Buffer] = ()) -> Self:
73
75
  for d in chain(data, iter):
74
76
  self.hash.update(d)
75
77
  return self
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "checkpointer"
3
- version = "2.14.8"
3
+ version = "2.14.9"
4
4
  requires-python = ">=3.11"
5
5
  dependencies = []
6
6
  authors = [
@@ -8,7 +8,7 @@ resolution-markers = [
8
8
 
9
9
  [[package]]
10
10
  name = "checkpointer"
11
- version = "2.14.8"
11
+ version = "2.14.9"
12
12
  source = { editable = "." }
13
13
 
14
14
  [package.dev-dependencies]
File without changes
File without changes
File without changes