checkpointer 2.14.10__tar.gz → 2.14.11__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.10 → checkpointer-2.14.11}/PKG-INFO +19 -1
  2. {checkpointer-2.14.10 → checkpointer-2.14.11}/README.md +18 -0
  3. {checkpointer-2.14.10 → checkpointer-2.14.11}/checkpointer/checkpoint.py +2 -1
  4. {checkpointer-2.14.10 → checkpointer-2.14.11}/checkpointer/storages/memory_storage.py +2 -0
  5. {checkpointer-2.14.10 → checkpointer-2.14.11}/pyproject.toml +1 -1
  6. {checkpointer-2.14.10 → checkpointer-2.14.11}/uv.lock +1 -1
  7. {checkpointer-2.14.10 → checkpointer-2.14.11}/.gitignore +0 -0
  8. {checkpointer-2.14.10 → checkpointer-2.14.11}/.python-version +0 -0
  9. {checkpointer-2.14.10 → checkpointer-2.14.11}/ATTRIBUTION.md +0 -0
  10. {checkpointer-2.14.10 → checkpointer-2.14.11}/LICENSE +0 -0
  11. {checkpointer-2.14.10 → checkpointer-2.14.11}/checkpointer/__init__.py +0 -0
  12. {checkpointer-2.14.10 → checkpointer-2.14.11}/checkpointer/fn_ident.py +0 -0
  13. {checkpointer-2.14.10 → checkpointer-2.14.11}/checkpointer/fn_string.py +0 -0
  14. {checkpointer-2.14.10 → checkpointer-2.14.11}/checkpointer/import_mappings.py +0 -0
  15. {checkpointer-2.14.10 → checkpointer-2.14.11}/checkpointer/object_hash.py +0 -0
  16. {checkpointer-2.14.10 → checkpointer-2.14.11}/checkpointer/print_checkpoint.py +0 -0
  17. {checkpointer-2.14.10 → checkpointer-2.14.11}/checkpointer/storages/__init__.py +0 -0
  18. {checkpointer-2.14.10 → checkpointer-2.14.11}/checkpointer/storages/pickle_storage.py +0 -0
  19. {checkpointer-2.14.10 → checkpointer-2.14.11}/checkpointer/storages/storage.py +0 -0
  20. {checkpointer-2.14.10 → checkpointer-2.14.11}/checkpointer/types.py +0 -0
  21. {checkpointer-2.14.10 → checkpointer-2.14.11}/checkpointer/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: checkpointer
3
- Version: 2.14.10
3
+ Version: 2.14.11
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
@@ -177,6 +177,24 @@ def process(
177
177
 
178
178
  In this example, the hash for `numbers` ignores order, `data_file` is hashed based on its contents rather than path, and changes to `log` don't affect caching.
179
179
 
180
+ ## 🔑 Custom Instance Hashing with `__objecthash__`
181
+
182
+ Any class can implement `__objecthash__` to control how its instances are hashed by `checkpointer`. When an instance is encountered during hashing, `checkpointer` calls `__objecthash__()` and hashes the returned value instead of inspecting the object's internals.
183
+
184
+ ```python
185
+ class Model:
186
+ def __init__(self, id: str, weights: list[float]):
187
+ self.id = id
188
+ self.weights = weights
189
+
190
+ def __objecthash__(self):
191
+ return self.id # Hash instances by their id only
192
+ ```
193
+
194
+ The return value of `__objecthash__` can be any Python value — a string, int, tuple, dict, or anything else `checkpointer` knows how to hash. This makes it easy to define a precise, stable identity for your objects without relying on pickle or attribute inspection.
195
+
196
+ Once defined, `__objecthash__` applies everywhere the class is used — as a function argument, captured variable, or nested value — with no need for `HashBy` annotations at each call site.
197
+
180
198
  ## 🎯 Capturing Global Variables
181
199
 
182
200
  `checkpointer` can include **captured global variables** in call hashes - these are globals your function reads during execution that may affect results.
@@ -160,6 +160,24 @@ def process(
160
160
 
161
161
  In this example, the hash for `numbers` ignores order, `data_file` is hashed based on its contents rather than path, and changes to `log` don't affect caching.
162
162
 
163
+ ## 🔑 Custom Instance Hashing with `__objecthash__`
164
+
165
+ Any class can implement `__objecthash__` to control how its instances are hashed by `checkpointer`. When an instance is encountered during hashing, `checkpointer` calls `__objecthash__()` and hashes the returned value instead of inspecting the object's internals.
166
+
167
+ ```python
168
+ class Model:
169
+ def __init__(self, id: str, weights: list[float]):
170
+ self.id = id
171
+ self.weights = weights
172
+
173
+ def __objecthash__(self):
174
+ return self.id # Hash instances by their id only
175
+ ```
176
+
177
+ The return value of `__objecthash__` can be any Python value — a string, int, tuple, dict, or anything else `checkpointer` knows how to hash. This makes it easy to define a precise, stable identity for your objects without relying on pickle or attribute inspection.
178
+
179
+ Once defined, `__objecthash__` applies everywhere the class is used — as a function argument, captured variable, or nested value — with no need for `HashBy` annotations at each call site.
180
+
163
181
  ## 🎯 Capturing Global Variables
164
182
 
165
183
  `checkpointer` can include **captured global variables** in call hashes - these are globals your function reads during execution that may affect results.
@@ -5,6 +5,7 @@ from datetime import datetime, timedelta
5
5
  from functools import cached_property, update_wrapper
6
6
  from inspect import Parameter, iscoroutine, signature, unwrap
7
7
  from pathlib import Path
8
+ from types import MethodType
8
9
  from typing import (
9
10
  Callable, Concatenate, Coroutine, Generic, Iterable,
10
11
  Literal, Self, Type, TypedDict, Unpack, overload,
@@ -151,7 +152,7 @@ class CachedFunction(Generic[Fn]):
151
152
  @property
152
153
  def fn(self) -> Fn:
153
154
  if self.bound:
154
- return self.ident.fn.__get__(self.bound[0], self.bound[0].__class__) # type: ignore
155
+ return MethodType(self.ident.fn, self.bound[0]) # type: ignore
155
156
  return self.ident.fn # type: ignore
156
157
 
157
158
  @cached_property
@@ -47,6 +47,8 @@ class MemoryStorage(Storage):
47
47
  for call_hash, (date, _) in list(calldict.items()):
48
48
  if self.expired_dt(date):
49
49
  del calldict[call_hash]
50
+ if not calldict:
51
+ del item_map[key]
50
52
 
51
53
  def clear(self):
52
54
  fn_path = self.fn_dir().parent
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "checkpointer"
3
- version = "2.14.10"
3
+ version = "2.14.11"
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.10"
11
+ version = "2.14.11"
12
12
  source = { editable = "." }
13
13
 
14
14
  [package.dev-dependencies]
File without changes