persidict 0.24.0__tar.gz → 0.26.0__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.

Potentially problematic release.


This version of persidict might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: persidict
3
- Version: 0.24.0
3
+ Version: 0.26.0
4
4
  Summary: Simple persistent key-value store for Python. Values are stored as files on a disk or as S3 objects on AWS cloud.
5
5
  Keywords: persistence,dicts,distributed,parallel
6
6
  Author: Vlad (Volodymyr) Pavlov
@@ -161,8 +161,9 @@ that simultaneously work with the same instance of a dictionary.
161
161
  `oldest_keys()`, `newest_values()`, `oldest_values()`,
162
162
  `get_params()`, `get_metaparams()`, and `get_default_metaparams()`,
163
163
  which are not available in native Python dicts.
164
- * You can use NO_CHANGE constant as a fake new value
165
- to avoid actually setting/updating a value.
164
+ * You can use KEEP_CURRENT constant as a fake new value
165
+ to avoid actually setting/updating a value. Or DELETE_CURRENT as
166
+ a fake new value to delete the previous value from a dictionary.
166
167
 
167
168
  ## Fine Tuning
168
169
 
@@ -128,8 +128,9 @@ that simultaneously work with the same instance of a dictionary.
128
128
  `oldest_keys()`, `newest_values()`, `oldest_values()`,
129
129
  `get_params()`, `get_metaparams()`, and `get_default_metaparams()`,
130
130
  which are not available in native Python dicts.
131
- * You can use NO_CHANGE constant as a fake new value
132
- to avoid actually setting/updating a value.
131
+ * You can use KEEP_CURRENT constant as a fake new value
132
+ to avoid actually setting/updating a value. Or DELETE_CURRENT as
133
+ a fake new value to delete the previous value from a dictionary.
133
134
 
134
135
  ## Fine Tuning
135
136
 
@@ -4,7 +4,7 @@ build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "persidict"
7
- version = "0.24.0"
7
+ version = "0.26.0"
8
8
  description = "Simple persistent key-value store for Python. Values are stored as files on a disk or as S3 objects on AWS cloud."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -27,4 +27,5 @@ from .safe_str_tuple import SafeStrTuple
27
27
  from .persi_dict import PersiDict
28
28
  from .file_dir_dict import FileDirDict
29
29
  from .s3_dict import S3Dict
30
- from .nochange_const import *
30
+ from .jokers import Joker, KeepCurrentFlag, DeleteCurrentFlag
31
+ from .jokers import KEEP_CURRENT, DELETE_CURRENT
@@ -12,7 +12,6 @@ from __future__ import annotations
12
12
  import os
13
13
  import random
14
14
  import time
15
- from abc import abstractmethod
16
15
  from typing import Any, Optional
17
16
 
18
17
  import joblib
@@ -21,7 +20,7 @@ import jsonpickle.ext.numpy as jsonpickle_numpy
21
20
  import jsonpickle.ext.pandas as jsonpickle_pandas
22
21
  import parameterizable
23
22
 
24
- from .nochange_const import NO_CHANGE
23
+ from .jokers import KEEP_CURRENT, DELETE_CURRENT, Joker
25
24
  from .safe_chars import replace_unsafe_chars
26
25
  from .safe_str_tuple import SafeStrTuple
27
26
  from .safe_str_tuple_signing import sign_safe_str_tuple, unsign_safe_str_tuple
@@ -317,7 +316,11 @@ class FileDirDict(PersiDict):
317
316
  def __setitem__(self, key:PersiDictKey, value:Any):
318
317
  """Set self[key] to value."""
319
318
 
320
- if value is NO_CHANGE:
319
+ if value is KEEP_CURRENT:
320
+ return
321
+
322
+ if value is DELETE_CURRENT:
323
+ self.delete_if_exists(key)
321
324
  return
322
325
 
323
326
  if isinstance(value, PersiDict):
@@ -0,0 +1,51 @@
1
+ """A singleton constant to indicate no change in a value.
2
+
3
+ When updating a value in a persistent dictionary,
4
+ use KEEP_CURRENT as the new value to indicate that
5
+ the existing value should remain unchanged.
6
+ """
7
+ from typing import Any
8
+
9
+ from parameterizable import (
10
+ ParameterizableClass
11
+ , register_parameterizable_class)
12
+
13
+
14
+ class Joker(ParameterizableClass):
15
+ _instances = {}
16
+
17
+ def get_params(self) -> dict[str, Any]:
18
+ return {}
19
+
20
+ def __new__(cls):
21
+ if cls not in Joker._instances:
22
+ Joker._instances[cls] = super().__new__(cls)
23
+ return Joker._instances[cls]
24
+
25
+
26
+ class KeepCurrentFlag(Joker):
27
+ """A singleton constant to indicate no change in a value.
28
+
29
+ When updating a value in a persistent dictionary,
30
+ use KeepCurrent as the new value to indicate that
31
+ the existing value (if any) should remain unchanged.
32
+ """
33
+ pass
34
+
35
+ class DeleteCurrentFlag(Joker):
36
+ """A singleton constant to indicate that the current value should be deleted.
37
+
38
+ When updating a value in a persistent dictionary,
39
+ use DeleteCurrentFlag as the new value to indicate that
40
+ the existing value (if any) should be removed from the dictionary.
41
+ """
42
+ pass
43
+
44
+ register_parameterizable_class(KeepCurrentFlag)
45
+ register_parameterizable_class(DeleteCurrentFlag)
46
+
47
+ KeepCurrent = KeepCurrentFlag()
48
+ KEEP_CURRENT = KeepCurrentFlag()
49
+
50
+ DeleteCurrent = DeleteCurrentFlag()
51
+ DELETE_CURRENT = DeleteCurrentFlag()
@@ -26,7 +26,7 @@ from parameterizable import ParameterizableClass
26
26
  from typing import Any, Sequence, Optional
27
27
  from collections.abc import MutableMapping
28
28
 
29
- from .nochange_const import NO_CHANGE
29
+ from .jokers import KEEP_CURRENT, DELETE_CURRENT, Joker
30
30
  from .safe_str_tuple import SafeStrTuple
31
31
 
32
32
  PersiDictKey = SafeStrTuple | Sequence[str] | str
@@ -161,9 +161,11 @@ class PersiDict(MutableMapping, ParameterizableClass):
161
161
 
162
162
  def __setitem__(self, key:PersiDictKey, value:Any):
163
163
  """Set self[key] to value."""
164
- if value is NO_CHANGE:
164
+ if value is KEEP_CURRENT:
165
165
  return
166
- if self.immutable_items:
166
+ elif value is DELETE_CURRENT:
167
+ self.delete_if_exists(key)
168
+ elif self.immutable_items:
167
169
  if key in self:
168
170
  raise KeyError("Can't modify an immutable key-value pair")
169
171
  raise NotImplementedError
@@ -216,7 +218,7 @@ class PersiDict(MutableMapping, ParameterizableClass):
216
218
  """
217
219
  # TODO: check edge cases to ensure the same semantics as standard dicts
218
220
  key = SafeStrTuple(key)
219
- assert not default is NO_CHANGE
221
+ assert not isinstance(default, Joker)
220
222
  if key in self:
221
223
  return self[key]
222
224
  else:
@@ -1,7 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import os
4
- from abc import abstractmethod
5
4
  from typing import Any, Optional
6
5
 
7
6
  import boto3
@@ -10,7 +9,7 @@ import parameterizable
10
9
  from .safe_str_tuple import SafeStrTuple
11
10
  from .safe_str_tuple_signing import sign_safe_str_tuple, unsign_safe_str_tuple
12
11
  from .persi_dict import PersiDict
13
- from .nochange_const import NO_CHANGE
12
+ from .jokers import KEEP_CURRENT, DELETE_CURRENT
14
13
  from .file_dir_dict import FileDirDict, PersiDictKey
15
14
 
16
15
  S3DICT_DEFAULT_BASE_DIR = "__s3_dict__"
@@ -191,7 +190,11 @@ class S3Dict(PersiDict):
191
190
  def __setitem__(self, key:PersiDictKey, value:Any):
192
191
  """Set self[key] to value. """
193
192
 
194
- if value is NO_CHANGE:
193
+ if value is KEEP_CURRENT:
194
+ return
195
+
196
+ if value is DELETE_CURRENT:
197
+ self.delete_if_exists(key)
195
198
  return
196
199
 
197
200
  if isinstance(value, PersiDict):
@@ -1,17 +0,0 @@
1
- """A singleton constant to indicate no change in a value.
2
-
3
- When updating a value in a persistent dictionary,
4
- use NO_CHANGE as the new value to indicate that
5
- the existing value should remain unchanged.
6
- """
7
-
8
- class NoChangeFlag:
9
- _instance = None
10
-
11
- def __new__(cls):
12
- if cls._instance is None:
13
- cls._instance = super().__new__(cls)
14
- return cls._instance
15
-
16
- NoChange = NoChangeFlag()
17
- NO_CHANGE = NoChangeFlag()