mm-std 0.5.3__py3-none-any.whl → 0.5.4__py3-none-any.whl
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.
mm_std/dict_utils.py
CHANGED
|
@@ -1,22 +1,49 @@
|
|
|
1
|
-
from collections import defaultdict
|
|
1
|
+
from collections import OrderedDict, defaultdict
|
|
2
2
|
from collections.abc import Mapping, MutableMapping
|
|
3
3
|
from decimal import Decimal
|
|
4
|
-
from typing import TypeVar,
|
|
4
|
+
from typing import TypeVar, overload
|
|
5
5
|
|
|
6
6
|
K = TypeVar("K")
|
|
7
7
|
V = TypeVar("V")
|
|
8
|
-
# TypeVar bound to MutableMapping with same K, V as defaults parameter
|
|
9
|
-
# 'type: ignore' needed because mypy can't handle TypeVar bounds with other TypeVars
|
|
10
|
-
DictType = TypeVar("DictType", bound=MutableMapping[K, V]) # type: ignore[valid-type]
|
|
11
8
|
|
|
12
9
|
|
|
10
|
+
@overload
|
|
13
11
|
def replace_empty_dict_entries(
|
|
14
|
-
data:
|
|
12
|
+
data: defaultdict[K, V],
|
|
15
13
|
defaults: Mapping[K, V] | None = None,
|
|
16
14
|
treat_zero_as_empty: bool = False,
|
|
17
15
|
treat_false_as_empty: bool = False,
|
|
18
16
|
treat_empty_string_as_empty: bool = True,
|
|
19
|
-
) ->
|
|
17
|
+
) -> defaultdict[K, V]: ...
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@overload
|
|
21
|
+
def replace_empty_dict_entries(
|
|
22
|
+
data: OrderedDict[K, V],
|
|
23
|
+
defaults: Mapping[K, V] | None = None,
|
|
24
|
+
treat_zero_as_empty: bool = False,
|
|
25
|
+
treat_false_as_empty: bool = False,
|
|
26
|
+
treat_empty_string_as_empty: bool = True,
|
|
27
|
+
) -> OrderedDict[K, V]: ...
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@overload
|
|
31
|
+
def replace_empty_dict_entries(
|
|
32
|
+
data: dict[K, V],
|
|
33
|
+
defaults: Mapping[K, V] | None = None,
|
|
34
|
+
treat_zero_as_empty: bool = False,
|
|
35
|
+
treat_false_as_empty: bool = False,
|
|
36
|
+
treat_empty_string_as_empty: bool = True,
|
|
37
|
+
) -> dict[K, V]: ...
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def replace_empty_dict_entries(
|
|
41
|
+
data: MutableMapping[K, V],
|
|
42
|
+
defaults: Mapping[K, V] | None = None,
|
|
43
|
+
treat_zero_as_empty: bool = False,
|
|
44
|
+
treat_false_as_empty: bool = False,
|
|
45
|
+
treat_empty_string_as_empty: bool = True,
|
|
46
|
+
) -> MutableMapping[K, V]:
|
|
20
47
|
"""
|
|
21
48
|
Replace empty entries in a dictionary with defaults or remove them entirely.
|
|
22
49
|
|
|
@@ -60,4 +87,4 @@ def replace_empty_dict_entries(
|
|
|
60
87
|
new_value = value
|
|
61
88
|
|
|
62
89
|
result[key] = new_value
|
|
63
|
-
return
|
|
90
|
+
return result
|
mm_std/json_utils.py
CHANGED
|
@@ -43,11 +43,8 @@ class ExtendedJSONEncoder(json.JSONEncoder):
|
|
|
43
43
|
serializer: Function that converts objects of this type to JSON-serializable data
|
|
44
44
|
|
|
45
45
|
Raises:
|
|
46
|
-
TypeError: If serializer is not callable
|
|
47
46
|
ValueError: If type_ is a built-in JSON type
|
|
48
47
|
"""
|
|
49
|
-
if not callable(serializer):
|
|
50
|
-
raise TypeError("Serializer must be callable")
|
|
51
48
|
if type_ in (str, int, float, bool, list, dict, type(None)):
|
|
52
49
|
raise ValueError(f"Cannot override built-in JSON type: {type_.__name__}")
|
|
53
50
|
cls._type_handlers[type_] = serializer
|
|
@@ -101,7 +98,7 @@ def _auto_register_optional_types() -> None:
|
|
|
101
98
|
"""Register handlers for optional dependencies if available."""
|
|
102
99
|
# Pydantic models
|
|
103
100
|
try:
|
|
104
|
-
from pydantic import BaseModel # type: ignore[import-not-found]
|
|
101
|
+
from pydantic import BaseModel # type: ignore[import-not-found] # noqa: PLC0415
|
|
105
102
|
|
|
106
103
|
ExtendedJSONEncoder.register(BaseModel, lambda obj: obj.model_dump())
|
|
107
104
|
except ImportError:
|
mm_std/random_utils.py
CHANGED
|
@@ -33,7 +33,7 @@ def random_decimal(from_value: Decimal, to_value: Decimal) -> Decimal:
|
|
|
33
33
|
from_int = int(from_value * multiplier)
|
|
34
34
|
to_int = int(to_value * multiplier)
|
|
35
35
|
|
|
36
|
-
random_int = random.randint(from_int, to_int)
|
|
36
|
+
random_int = random.randint(from_int, to_int) # nosec B311
|
|
37
37
|
return Decimal(random_int) / Decimal(multiplier)
|
|
38
38
|
|
|
39
39
|
|
|
@@ -68,5 +68,5 @@ def random_datetime(
|
|
|
68
68
|
if total_seconds == 0:
|
|
69
69
|
return from_time
|
|
70
70
|
|
|
71
|
-
random_seconds = random.uniform(0, total_seconds)
|
|
71
|
+
random_seconds = random.uniform(0, total_seconds) # nosec B311
|
|
72
72
|
return from_time + timedelta(seconds=random_seconds)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
mm_std/__init__.py,sha256=V1na3dOxX52p44hOwhHFaIgrZEHR3yEjFdmSIcB2n0c,715
|
|
2
|
+
mm_std/date_utils.py,sha256=aFdIacoNgDSPGeUkZihXZADd86TeHu4hr1uIT9zcqvw,1732
|
|
3
|
+
mm_std/dict_utils.py,sha256=Gq_LYuidf24SWvzNmUx8wVPGuop9263GOxcIflB__uQ,2850
|
|
4
|
+
mm_std/json_utils.py,sha256=NuDomTThfCkJBCmfQ6vkr7dvChKGsuLoAyLW0TON_dQ,3997
|
|
5
|
+
mm_std/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
mm_std/random_utils.py,sha256=3q5ZylCqfFHKN3VaDXuy4heo8C1jNbLHNNOFvyYJoZY,2253
|
|
7
|
+
mm_std/str_utils.py,sha256=I6vVC81dGBDTHm7FxW-ka5OlUPjHmgagei7Zjld65lk,1520
|
|
8
|
+
mm_std/subprocess_utils.py,sha256=6Bkw6ZYHT1NLIYbQUV9LGkBzUl5RtaVzMJiLJrTGq48,2507
|
|
9
|
+
mm_std-0.5.4.dist-info/METADATA,sha256=SnanvJ0gBE6Y_5-dSOkUaH5BVV482k3KPXFhuUKeV5Q,74
|
|
10
|
+
mm_std-0.5.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
11
|
+
mm_std-0.5.4.dist-info/RECORD,,
|
mm_std-0.5.3.dist-info/RECORD
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
mm_std/__init__.py,sha256=V1na3dOxX52p44hOwhHFaIgrZEHR3yEjFdmSIcB2n0c,715
|
|
2
|
-
mm_std/date_utils.py,sha256=aFdIacoNgDSPGeUkZihXZADd86TeHu4hr1uIT9zcqvw,1732
|
|
3
|
-
mm_std/dict_utils.py,sha256=GVegQXTIo3tzLGbBkiUSGTJkfaD5WWwz6OQnw9KcXlg,2275
|
|
4
|
-
mm_std/json_utils.py,sha256=3tOv2rowc9B18TpJyGSci1MvPEj5XogRy3qrJ1W_7Bg,4129
|
|
5
|
-
mm_std/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
-
mm_std/random_utils.py,sha256=x3uNuKjKY8GxYjbnOq0LU1pGXhI2wezpH2K-t9hrhfA,2225
|
|
7
|
-
mm_std/str_utils.py,sha256=I6vVC81dGBDTHm7FxW-ka5OlUPjHmgagei7Zjld65lk,1520
|
|
8
|
-
mm_std/subprocess_utils.py,sha256=6Bkw6ZYHT1NLIYbQUV9LGkBzUl5RtaVzMJiLJrTGq48,2507
|
|
9
|
-
mm_std-0.5.3.dist-info/METADATA,sha256=GbbfchD5CvEJq3n5ZMNJyNPwUwvfOd_bJxj7tc6iGqY,74
|
|
10
|
-
mm_std-0.5.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
11
|
-
mm_std-0.5.3.dist-info/RECORD,,
|
|
File without changes
|