funkycache 1.0.3__tar.gz → 1.0.5__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: funkycache
3
- Version: 1.0.3
3
+ Version: 1.0.5
4
4
  Summary: A SQLite-backed function cache that tracks file dependencies
5
5
  Author-email: Alex Chan <alex@alexwlchan.net>
6
6
  Maintainer-email: Alex Chan <alex@alexwlchan.net>
@@ -21,7 +21,8 @@ Dynamic: license-file
21
21
  funkycache is a disk-backed cache for Python functions that tracks file dependencies.
22
22
  I use it in my static site generator to cache the output of expensive functions.
23
23
 
24
- Example:
24
+ To cache the output of a function, create a `FunkyCache` instance, then apply the `cache.register` decorator.
25
+ For example:
25
26
 
26
27
  ```python
27
28
  from funkycache import FunkyCache
@@ -50,6 +51,22 @@ If those dependent values change, the function's cache is invalidated, and the n
50
51
  **Note:** funkycache does not watch the filesystem.
51
52
  It is your responsibility to notify it of changes to dependent files, or they will be noticed when the Python process restarts.
52
53
 
54
+ ## Caching requirements
55
+
56
+ To cache a function with funkycache, the function must:
57
+
58
+ * Have a type hint with a return annotation
59
+ * Always return an identical result when given identical inputs
60
+ * Not have any side effects (for example, creating a file)
61
+
62
+ ## Design
63
+
64
+ * Each function has an independent cache
65
+ * Cache keys are the function arguments, serialised as JSON and hashed using XXH64
66
+ * Cache values are the return value, serialised as JSON
67
+
68
+ For more information about how funkycache works, read [my design notes][me-funkycache-intro].
69
+
53
70
  ## Installation
54
71
 
55
72
  Install using pip:
@@ -61,3 +78,6 @@ $ pip install funkycache
61
78
  ## License
62
79
 
63
80
  This project is shared under the [MIT license](./LICENSE).
81
+
82
+ [me-funkycache-intro]: https://alexwlchan.net/2026/funkycache/
83
+ [wiki-pure]: https://en.wikipedia.org/wiki/Pure_function
@@ -3,7 +3,8 @@
3
3
  funkycache is a disk-backed cache for Python functions that tracks file dependencies.
4
4
  I use it in my static site generator to cache the output of expensive functions.
5
5
 
6
- Example:
6
+ To cache the output of a function, create a `FunkyCache` instance, then apply the `cache.register` decorator.
7
+ For example:
7
8
 
8
9
  ```python
9
10
  from funkycache import FunkyCache
@@ -32,6 +33,22 @@ If those dependent values change, the function's cache is invalidated, and the n
32
33
  **Note:** funkycache does not watch the filesystem.
33
34
  It is your responsibility to notify it of changes to dependent files, or they will be noticed when the Python process restarts.
34
35
 
36
+ ## Caching requirements
37
+
38
+ To cache a function with funkycache, the function must:
39
+
40
+ * Have a type hint with a return annotation
41
+ * Always return an identical result when given identical inputs
42
+ * Not have any side effects (for example, creating a file)
43
+
44
+ ## Design
45
+
46
+ * Each function has an independent cache
47
+ * Cache keys are the function arguments, serialised as JSON and hashed using XXH64
48
+ * Cache values are the return value, serialised as JSON
49
+
50
+ For more information about how funkycache works, read [my design notes][me-funkycache-intro].
51
+
35
52
  ## Installation
36
53
 
37
54
  Install using pip:
@@ -43,3 +60,6 @@ $ pip install funkycache
43
60
  ## License
44
61
 
45
62
  This project is shared under the [MIT license](./LICENSE).
63
+
64
+ [me-funkycache-intro]: https://alexwlchan.net/2026/funkycache/
65
+ [wiki-pure]: https://en.wikipedia.org/wiki/Pure_function
@@ -30,6 +30,7 @@ import xxhash
30
30
 
31
31
  from .storage import (
32
32
  CacheStorage,
33
+ LazyCacheStorage,
33
34
  MemoryCacheStorage,
34
35
  SQLiteCacheStorage,
35
36
  CannotOverwriteValueException,
@@ -322,13 +323,16 @@ class FunkyCache:
322
323
  # similar-looking caches which are presumably stale.
323
324
  # TODO: Check if the cache was accessed recently, which
324
325
  # might indicate another process still using it.
325
- self._root.mkdir(exist_ok=True, parents=True)
326
326
  db_path = self._root / f"{identifier}.{input_sig}.db"
327
- storage = SQLiteCacheStorage[R](db_path, data_type=data_type)
328
327
  for f in self._root.glob(f"{identifier}.*.db*"):
329
328
  if f != db_path:
330
329
  f.unlink()
331
- return storage
330
+
331
+ return LazyCacheStorage(
332
+ create_underlying=lambda: SQLiteCacheStorage[R](
333
+ db_path, data_type=data_type
334
+ )
335
+ )
332
336
  case _: # pragma: no cover
333
337
  raise TypeError(f"unrecognised storage: {self._storage!r}")
334
338
 
@@ -379,8 +383,10 @@ class FunkyCache:
379
383
  continue
380
384
 
381
385
  # This cache depends on a path that changed! Create a new cache.
382
- if isinstance(known_cache.storage, SQLiteCacheStorage):
383
- known_cache.storage.close()
386
+ try:
387
+ known_cache.storage.close() # type: ignore
388
+ except AttributeError:
389
+ pass
384
390
 
385
391
  known_cache.storage = self._create_storage(
386
392
  func_name=known_cache.func_name,
@@ -6,9 +6,10 @@ a collection of arguments to the return value.
6
6
  """
7
7
 
8
8
  from abc import ABC, abstractmethod
9
+ from collections.abc import Callable
9
10
  import dataclasses
10
11
  from datetime import datetime, timezone
11
- from functools import cache
12
+ import functools
12
13
  import json
13
14
  from pathlib import Path
14
15
  import sqlite3
@@ -152,6 +153,9 @@ class SQLiteCacheStorage[V](TypedCacheStorage[V]):
152
153
  con: sqlite3.Connection
153
154
 
154
155
  def __init__(self, database: str | Path, *, data_type: Any):
156
+ if database != ":memory:":
157
+ Path(database).parent.mkdir(exist_ok=True, parents=True)
158
+
155
159
  self.con = sqlite3.connect(database)
156
160
  self.con.execute("PRAGMA journal_mode = WAL;")
157
161
  self.con.execute("PRAGMA synchronous = NORMAL;")
@@ -299,35 +303,49 @@ class SQLiteCacheStorage[V](TypedCacheStorage[V]):
299
303
  raise KeyError(key)
300
304
 
301
305
 
302
- def _make_json_compatible(value: Any) -> Any:
306
+ class LazyCacheStorage[V](CacheStorage[V]):
303
307
  """
304
- Recursively walk an arbitrary structure and prepare it for JSON encoding.
308
+ LazyCacheStorage is a lazy wrapper around an underlying CacheStorage
309
+ instance, and doesn't instantiate it until somebody interacts with
310
+ the cache.
305
311
  """
306
- if isinstance(value, dict):
307
- return {str(k): _make_json_compatible(v) for k, v in value.items()}
308
- elif isinstance(value, (list, tuple, set)):
309
- return [_make_json_compatible(item) for item in value]
310
- else:
311
- return value
312
312
 
313
+ _create_underlying: Callable[[], CacheStorage[V]]
314
+ _underlying: CacheStorage[V] | None
313
315
 
314
- @cache
315
- def _get_type_adapter(target_type: Any) -> TypeAdapter:
316
- """
317
- Return a TypeAdapter for the given Pydantic type.
316
+ def __init__(self, create_underlying: Callable[[], CacheStorage[V]]):
317
+ self._create_underlying = create_underlying
318
+ self._underlying = None
318
319
 
319
- The type adapter is cached, so schema generation only runs once
320
- per unique type.
321
- """
322
- return TypeAdapter(target_type)
320
+ def __getattr__(self, name: str) -> Any:
321
+ """
322
+ When looking up any property or method, forward to the underlying
323
+ cache storage, ensuring it exists first.
324
+ """
325
+ if self._underlying is None:
326
+ self._underlying = self._create_underlying()
327
+ return getattr(self._underlying, name)
323
328
 
329
+ def set(self, key: dict[str, Any], value: V) -> None:
330
+ """
331
+ Save a key-value pair in the cache.
324
332
 
325
- def _should_hash(v: Any) -> bool:
326
- """
327
- Return whether the value is a long string that should be hashed
328
- before JSON-encoding the key.
329
- """
330
- return isinstance(v, str) and len(v) > 512
333
+ Throws an exception if you overwrite an existing key with
334
+ a different value.
335
+ """
336
+ if self._underlying is None:
337
+ self._underlying = self._create_underlying()
338
+ return self._underlying.set(key, value)
339
+
340
+ def get(self, key: dict[str, Any]) -> V:
341
+ """
342
+ Look up the value of a key in the cache.
343
+
344
+ Throws a KeyError if you look up a key which isn't in the cache.
345
+ """
346
+ if self._underlying is None:
347
+ self._underlying = self._create_underlying()
348
+ return self._underlying.get(key)
331
349
 
332
350
 
333
351
  def _encode_key_as_json(key: dict[str, Any]) -> str:
@@ -338,37 +356,99 @@ def _encode_key_as_json(key: dict[str, Any]) -> str:
338
356
  serialisation as JSON. It is possible for values of different types
339
357
  to collide.
340
358
 
359
+ JSON encoding is a significant bottleneck, so we are trying to reduce
360
+ the JSON object to be as small as possible before encoding it.
361
+
341
362
  This function must not mutate its input.
342
363
  """
343
- overrides: dict[str, Any] = {}
344
-
345
- for name, val in key.items():
346
- if _should_hash(val):
347
- overrides[name] = _hash(val)
348
-
349
- elif isinstance(val, dict):
350
- if any(_should_hash(v) for v in val.values()):
351
- overrides[name] = {
352
- k: _hash(v) if _should_hash(v) else v for k, v in val.items()
353
- }
364
+ # TODO: How do we handle lazy generators/iterators as the input key?
354
365
 
355
- elif isinstance(val, BaseModel) or dataclasses.is_dataclass(val):
356
- adapter = _get_type_adapter(type(val))
357
- overrides[name] = {
358
- k: _hash(v) if _should_hash(v) else v
359
- for k, v in adapter.dump_python(val, mode="json").items()
360
- }
361
-
362
- reduced_key = {**key, **overrides}
366
+ reduced_key = {k: _process_value(v) for k, v in key.items()}
363
367
 
364
368
  try:
365
- return json.dumps(reduced_key, sort_keys=True, default=str)
369
+ return json.dumps(
370
+ reduced_key, sort_keys=True, default=str, separators=(",", ":")
371
+ )
366
372
  except TypeError:
367
373
  clean_key = _make_json_compatible(reduced_key)
368
- return json.dumps(clean_key, sort_keys=True, default=str)
374
+ return json.dumps(clean_key, sort_keys=True, default=str, separators=(",", ":"))
375
+
376
+
377
+ def _process_value(val: Any) -> Any:
378
+ """
379
+ Prepare a single value for JSON encoding.
380
+ """
381
+ # Primitive types: return directly and skip the isinstance() checks.
382
+ # Large strings should be hashed.
383
+ if val is None or type(val) in (str, int, float, bool):
384
+ if isinstance(val, str) and len(val) > 256:
385
+ return _hash(val)
386
+ return val
387
+
388
+ # Dictionaries: walk recursively, and omit keys for empty values.
389
+ elif isinstance(val, dict):
390
+ return {k: _process_value(v) for k, v in val.items() if v}
391
+
392
+ # Lists and tuples: walk recursively. If a list/tuple contains a list
393
+ # of dictionaries, extract the keys/values into separate lists to
394
+ # avoid repeating the keys in the JSON.
395
+ elif isinstance(val, (list, tuple)):
396
+ processed_items = [_process_value(v) for v in val]
397
+
398
+ if len(processed_items) <= 1:
399
+ return processed_items
400
+
401
+ if all(isinstance(item, dict) for item in processed_items):
402
+ all_keys = set().union(*(item.keys() for item in processed_items))
403
+ sorted_keys = sorted(all_keys)
404
+
405
+ values_matrix = [
406
+ [item.get(k) for k in sorted_keys] for item in processed_items
407
+ ]
408
+
409
+ return {"_keys": sorted_keys, "_values": values_matrix}
410
+
411
+ return processed_items
412
+
413
+ # Pydantic models and dataclasses: convert to dicts.
414
+ #
415
+ # This comes after the isinstance(…, dict) check because every Pydantic
416
+ # value will hit this branch and the dict() branch, but some values can
417
+ # go directly into the dict() branch. This reduces isinstance and
418
+ # is_dataclass calls.
419
+ elif isinstance(val, BaseModel) or dataclasses.is_dataclass(val):
420
+ adapter = _get_type_adapter(type(val))
421
+ dumped = adapter.dump_python(val, mode="json")
422
+ return _process_value(dumped)
423
+
424
+ else:
425
+ return val
426
+
427
+
428
+ @functools.cache
429
+ def _get_type_adapter(target_type: Any) -> TypeAdapter:
430
+ """
431
+ Return a TypeAdapter for the given Pydantic type.
432
+
433
+ The type adapter is cached, so schema generation only runs once
434
+ per unique type.
435
+ """
436
+ return TypeAdapter(target_type)
437
+
438
+
439
+ def _make_json_compatible(value: Any) -> Any:
440
+ """
441
+ Recursively walk an arbitrary structure and prepare it for JSON encoding.
442
+ """
443
+ if isinstance(value, dict):
444
+ return {str(k): _make_json_compatible(v) for k, v in value.items()}
445
+ elif isinstance(value, (list, tuple, set)):
446
+ return [_make_json_compatible(item) for item in value]
447
+ else:
448
+ return value
369
449
 
370
450
 
371
- @cache
451
+ @functools.cache
372
452
  def _hash(s: str) -> str:
373
453
  """
374
454
  Hash a string to reduce it to a fixed size.
@@ -2,4 +2,4 @@
2
2
  The FunkyCache version.
3
3
  """
4
4
 
5
- __version__ = "1.0.3"
5
+ __version__ = "1.0.5"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: funkycache
3
- Version: 1.0.3
3
+ Version: 1.0.5
4
4
  Summary: A SQLite-backed function cache that tracks file dependencies
5
5
  Author-email: Alex Chan <alex@alexwlchan.net>
6
6
  Maintainer-email: Alex Chan <alex@alexwlchan.net>
@@ -21,7 +21,8 @@ Dynamic: license-file
21
21
  funkycache is a disk-backed cache for Python functions that tracks file dependencies.
22
22
  I use it in my static site generator to cache the output of expensive functions.
23
23
 
24
- Example:
24
+ To cache the output of a function, create a `FunkyCache` instance, then apply the `cache.register` decorator.
25
+ For example:
25
26
 
26
27
  ```python
27
28
  from funkycache import FunkyCache
@@ -50,6 +51,22 @@ If those dependent values change, the function's cache is invalidated, and the n
50
51
  **Note:** funkycache does not watch the filesystem.
51
52
  It is your responsibility to notify it of changes to dependent files, or they will be noticed when the Python process restarts.
52
53
 
54
+ ## Caching requirements
55
+
56
+ To cache a function with funkycache, the function must:
57
+
58
+ * Have a type hint with a return annotation
59
+ * Always return an identical result when given identical inputs
60
+ * Not have any side effects (for example, creating a file)
61
+
62
+ ## Design
63
+
64
+ * Each function has an independent cache
65
+ * Cache keys are the function arguments, serialised as JSON and hashed using XXH64
66
+ * Cache values are the return value, serialised as JSON
67
+
68
+ For more information about how funkycache works, read [my design notes][me-funkycache-intro].
69
+
53
70
  ## Installation
54
71
 
55
72
  Install using pip:
@@ -61,3 +78,6 @@ $ pip install funkycache
61
78
  ## License
62
79
 
63
80
  This project is shared under the [MIT license](./LICENSE).
81
+
82
+ [me-funkycache-intro]: https://alexwlchan.net/2026/funkycache/
83
+ [wiki-pure]: https://en.wikipedia.org/wiki/Pure_function
@@ -778,11 +778,16 @@ class TestSQLiteFunkyCache(FunkyCacheTestSuite):
778
778
  root = tmp_path / ".cache"
779
779
  c = FunkyCache(storage="sqlite", root=root)
780
780
 
781
- @c.register(files=[tmp_path / "greeting.txt"])
782
- def double(n: int) -> int:
783
- return n * 2
781
+ p = tmp_path / "greeting.txt"
782
+ greeting1 = "bonjour monde"
783
+ greeting2 = "hello world"
784
784
 
785
- assert double(5) == 10
785
+ @c.register(files=[p])
786
+ def get_size() -> int:
787
+ return Path(p).stat().st_size
788
+
789
+ p.write_text(greeting1)
790
+ assert get_size() == len(greeting1)
786
791
 
787
792
  # After populating the cache, there's a single set of SQLite files
788
793
  # in the .cache directory
@@ -790,11 +795,12 @@ class TestSQLiteFunkyCache(FunkyCacheTestSuite):
790
795
  assert len(stem1) == 1
791
796
 
792
797
  # Invalidate the cache
793
- p = tmp_path / "greeting.txt"
794
- p.write_text("hello world")
798
+ p.write_text(greeting2)
795
799
  c.notify_path_change(p)
796
800
 
797
- # There should be a new set of SQLite files in the .cache directory
801
+ # After we call the function again, it creates a different SQLite db
802
+ # in the .cache directory
803
+ assert get_size() == len(greeting2)
798
804
  stem2 = {p.stem for p in root.iterdir()}
799
805
  assert len(stem2) == 1
800
806
  assert stem1 != stem2
@@ -926,6 +932,28 @@ class TestSQLiteFunkyCache(FunkyCacheTestSuite):
926
932
  def double(n: int) -> int: # pragma: no cover
927
933
  return n * 2
928
934
 
935
+ def test_db_is_lazy(self, tmp_path: Path) -> None:
936
+ """
937
+ The underlying SQLite database is only created when you interact
938
+ with it for the first time; empty caches are never created.
939
+ """
940
+ cache_root = tmp_path / ".funkycache/tests"
941
+
942
+ # Creating a FunkyCache instance doesn't create the db
943
+ cache = FunkyCache(storage="sqlite", root=cache_root)
944
+ assert not cache_root.exists()
945
+
946
+ # Registering a function doesn't create the db
947
+ @cache.register
948
+ def greet(name: str) -> str:
949
+ return f"Hello {name}!"
950
+
951
+ assert not cache_root.exists()
952
+
953
+ # Creating a cache entry creates the db
954
+ assert greet("Alex") == "Hello Alex!"
955
+ assert cache_root.exists()
956
+
929
957
 
930
958
  def test_canonical_name_varies_by_path(tmp_path: Path) -> None:
931
959
  """
@@ -19,6 +19,7 @@ from _pytest.mark.structures import ParameterSet
19
19
  from funkycache.storage import (
20
20
  CacheStorage,
21
21
  MemoryCacheStorage,
22
+ LazyCacheStorage,
22
23
  SQLiteCacheStorage,
23
24
  CannotOverwriteValueException,
24
25
  _encode_key_as_json,
@@ -247,6 +248,101 @@ class TestSQLiteCacheStorage(CacheStorageTestSuite):
247
248
  with pytest.raises(sqlite3.OperationalError, match="no such column: key"):
248
249
  SQLiteCacheStorage[int](db_path, data_type="int")
249
250
 
251
+ def test_creates_parent_dir(self, tmp_path: Path) -> None:
252
+ """
253
+ Creating the storage creates the parent directory for the
254
+ database file.
255
+ """
256
+ db_path = tmp_path / "a/b/c/cache.db"
257
+
258
+ with SQLiteCacheStorage[int](db_path, data_type=int):
259
+ pass
260
+
261
+ assert db_path.exists()
262
+
263
+
264
+ class LazyCacheStorageTestSuite(CacheStorageTestSuite):
265
+ """
266
+ Tests for LazyCacheStorage.
267
+ """
268
+
269
+ def test_storage_is_lazy(self, tmp_path: Path) -> None:
270
+ """
271
+ The underlying storage isn't created until you interact with
272
+ the storage.
273
+ """
274
+ with self.create_storage(tmp_path, data_type=str) as storage:
275
+ assert isinstance(storage, LazyCacheStorage)
276
+ assert storage._underlying is None
277
+
278
+ with pytest.raises(KeyError):
279
+ storage.get({"one": 1})
280
+
281
+ assert storage._underlying is not None
282
+
283
+ def test_unknown_getattr_is_forwarded_to_underlying(self, tmp_path: Path) -> None:
284
+ """
285
+ Looking up an unknown attribute with __getattr__ is forwarded
286
+ to the underlying storage.
287
+ """
288
+ with self.create_storage(tmp_path, data_type=str) as storage:
289
+ assert isinstance(storage, LazyCacheStorage)
290
+ assert storage._underlying is None
291
+
292
+ with pytest.raises(AttributeError):
293
+ getattr(storage, "does_not_exist")
294
+
295
+ assert storage._underlying is not None
296
+
297
+
298
+ class TestLazyMemoryCacheStorage(LazyCacheStorageTestSuite, TestMemoryCacheStorage):
299
+ """
300
+ Tests for MemoryCacheStorage wrapped in LazyCacheStorage.
301
+ """
302
+
303
+ @contextmanager
304
+ def create_storage[V](
305
+ self, tmp_path: Path, data_type: Any
306
+ ) -> Generator[CacheStorage[V]]:
307
+ """
308
+ Create a lazy cache storage backend.
309
+ """
310
+ yield LazyCacheStorage(create_underlying=lambda: MemoryCacheStorage())
311
+
312
+
313
+ class TestLazySQLiteCacheStorage(LazyCacheStorageTestSuite, TestSQLiteCacheStorage):
314
+ """
315
+ Tests for SQLiteCacheStorage wrapped in LazyCacheStorage.
316
+ """
317
+
318
+ @contextmanager
319
+ def create_storage[V](
320
+ self, tmp_path: Path, data_type: Any
321
+ ) -> Generator[CacheStorage[V]]:
322
+ """
323
+ Create a lazy cache storage backend.
324
+ """
325
+ storage = LazyCacheStorage(
326
+ create_underlying=lambda: SQLiteCacheStorage(
327
+ ":memory:", data_type=data_type
328
+ )
329
+ )
330
+ yield storage
331
+ storage.close()
332
+
333
+ def test_db_file_not_created_if_unused(self, tmp_path: Path) -> None:
334
+ """
335
+ If you never interact with the cache, neither the database
336
+ nor the enclosing folder are created.
337
+ """
338
+ db_path = tmp_path / "a/b/c/example.db"
339
+
340
+ with self.create_storage(db_path, data_type=str):
341
+ pass
342
+
343
+ assert not db_path.exists()
344
+ assert not db_path.parent.exists()
345
+
250
346
 
251
347
  class Shape(BaseModel):
252
348
  """A basic model that uses Pydantic."""
@@ -264,31 +360,48 @@ class Greeting:
264
360
 
265
361
 
266
362
  KEY_ENCODING_TEST_CASES: list[ParameterSet] = [
267
- pytest.param({"n": "one"}, '{"n": "one"}', id="str"),
268
- pytest.param({"n": 1}, '{"n": 1}', id="int"),
363
+ pytest.param({"n": "one"}, '{"n":"one"}', id="str"),
364
+ pytest.param({"n": 1}, '{"n":1}', id="int"),
365
+ pytest.param(
366
+ {"n": ["one", "uno", "eins"]}, '{"n":["one","uno","eins"]}', id="list"
367
+ ),
368
+ pytest.param(
369
+ {"n": ("one", "uno", "eins")}, '{"n":["one","uno","eins"]}', id="tuple"
370
+ ),
371
+ pytest.param({"n": []}, '{"n":[]}', id="empty_list"),
372
+ pytest.param({"n": [{"en": "one"}]}, '{"n":[{"en":"one"}]}', id="list_1"),
373
+ pytest.param(
374
+ {
375
+ "n": [
376
+ {"lang": "en", "val": "one"},
377
+ {"lang": "fr", "val": "un"},
378
+ {"lang": "de", "val": "eins"},
379
+ ]
380
+ },
381
+ '{"n":{"_keys":["lang","val"],"_values":[["en","one"],["fr","un"],["de","eins"]]}}',
382
+ id="list_many",
383
+ ),
269
384
  pytest.param(
270
385
  {"n": Shape(sides=4, colour="red")},
271
- '{"n": {"colour": "red", "sides": 4}}',
386
+ '{"n":{"colour":"red","sides":4}}',
272
387
  id="pydantic",
273
388
  ),
274
389
  pytest.param(
275
390
  {"n": Greeting(name="alex", message="hello")},
276
- '{"n": {"message": "hello", "name": "alex"}}',
391
+ '{"n":{"message":"hello","name":"alex"}}',
277
392
  id="dataclass",
278
393
  ),
279
394
  pytest.param(
280
395
  {"long": "a" * 5000, "short": "a"},
281
- '{"long": "xxh64:b2b67943d4803cd6", "short": "a"}',
396
+ '{"long":"xxh64:b2b67943d4803cd6","short":"a"}',
282
397
  id="long_str",
283
398
  ),
284
399
  pytest.param(
285
400
  {"n": {"long": "a" * 5000, "short": "a"}},
286
- '{"n": {"long": "xxh64:b2b67943d4803cd6", "short": "a"}}',
401
+ '{"n":{"long":"xxh64:b2b67943d4803cd6","short":"a"}}',
287
402
  id="long_str",
288
403
  ),
289
- pytest.param(
290
- {"n": {Path("1"): "one"}}, '{"n": {"1": "one"}}', id="nested_path_key"
291
- ),
404
+ pytest.param({"n": {Path("1"): "one"}}, '{"n":{"1":"one"}}', id="nested_path_key"),
292
405
  ]
293
406
 
294
407
 
File without changes
File without changes
File without changes