mm-std 0.3.6__py3-none-any.whl → 0.3.8__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/__init__.py
CHANGED
@@ -41,6 +41,7 @@ from .result import Ok as Ok
|
|
41
41
|
from .result import Result as Result
|
42
42
|
from .result import try_ok as try_ok
|
43
43
|
from .str import number_with_separator as number_with_separator
|
44
|
+
from .str import str_contains_any as str_contains_any
|
44
45
|
from .str import str_ends_with_any as str_ends_with_any
|
45
46
|
from .str import str_starts_with_any as str_starts_with_any
|
46
47
|
from .str import str_to_list as str_to_list
|
mm_std/dict.py
CHANGED
@@ -2,35 +2,14 @@ def replace_empty_dict_values(
|
|
2
2
|
data: dict[object, object],
|
3
3
|
defaults: dict[object, object] | None = None,
|
4
4
|
zero_is_empty: bool = False,
|
5
|
+
false_is_empty: bool = False,
|
5
6
|
) -> dict[object, object]:
|
6
|
-
"""
|
7
|
-
Replace empty values in a dictionary with provided default values, or remove them if no default exists.
|
8
|
-
|
9
|
-
An "empty" value is defined as one of the following:
|
10
|
-
- None
|
11
|
-
- An empty string ("")
|
12
|
-
|
13
|
-
If the flag `zero_is_empty` is True, the numeric value 0 is also considered empty.
|
14
|
-
|
15
|
-
For each key in the input dictionary `data`, if its value is empty, the function checks the
|
16
|
-
`defaults` dictionary for a replacement. If a default exists, it uses that value; otherwise, the
|
17
|
-
key is omitted from the resulting dictionary.
|
18
|
-
|
19
|
-
Parameters:
|
20
|
-
data (dict[object, object]): The input dictionary with key-value pairs to process.
|
21
|
-
defaults (dict[object, object] | None, optional): A dictionary of default values to use as
|
22
|
-
replacements for empty entries. If None, no default replacements are applied.
|
23
|
-
zero_is_empty (bool, optional): If True, treats the value 0 as empty. Defaults to False.
|
24
|
-
|
25
|
-
Returns:
|
26
|
-
dict[object, object]: A new dictionary with empty values replaced by defaults or removed if no
|
27
|
-
default is provided.
|
28
|
-
"""
|
7
|
+
"""Replace empty values in a dictionary with provided default values, or remove them if no default exists."""
|
29
8
|
if defaults is None:
|
30
9
|
defaults = {}
|
31
10
|
result = {}
|
32
11
|
for key, value in data.items():
|
33
|
-
if value is None or value == "" or (zero_is_empty and value == 0):
|
12
|
+
if value is None or value == "" or (zero_is_empty and value == 0) or (false_is_empty and value is False):
|
34
13
|
value = defaults.get(key, None) # noqa: PLW2901
|
35
14
|
if value is not None:
|
36
15
|
result[key] = value
|
mm_std/str.py
CHANGED
@@ -70,6 +70,11 @@ def str_ends_with_any(value: str, prefixes: list[str]) -> bool:
|
|
70
70
|
return any(value.endswith(prefix) for prefix in prefixes)
|
71
71
|
|
72
72
|
|
73
|
+
def str_contains_any(value: str, substrings: list[str]) -> bool:
|
74
|
+
"""Check if str contains any of the given substrings"""
|
75
|
+
return any(substring in value for substring in substrings)
|
76
|
+
|
77
|
+
|
73
78
|
def split_on_plus_minus_tokens(value: str) -> list[str]:
|
74
79
|
value = "".join(value.split())
|
75
80
|
if not value:
|
@@ -1,10 +1,10 @@
|
|
1
|
-
mm_std/__init__.py,sha256=
|
1
|
+
mm_std/__init__.py,sha256=wzKZe6qMG7cmZLqnA-thfr4QaFaPudJzcQKqLsfZeB8,2500
|
2
2
|
mm_std/command.py,sha256=ze286wjUjg0QSTgIu-2WZks53_Vclg69UaYYgPpQvCU,1283
|
3
3
|
mm_std/concurrency.py,sha256=4kKLhde6YQYsjJJjH6K5eMQj6FtegEz55Mo5TmhQMM0,5242
|
4
4
|
mm_std/config.py,sha256=4DGzjLO8TYno1xF8wj2hRaw2-gfNzt_W1_bt7w8ovno,1874
|
5
5
|
mm_std/crypto.py,sha256=jdk0_TCmeU0pPXMyz9xH6kQHSjjZ9GcGClBwQps5vBo,340
|
6
6
|
mm_std/date.py,sha256=976eEkSONuNqHQBgSRu8hrtH23tJqztbmHFHLdbP2TY,1879
|
7
|
-
mm_std/dict.py,sha256=
|
7
|
+
mm_std/dict.py,sha256=6GkhJPXD0LiJDxPcYe6jPdEDw-MN7P7mKu6U5XxwYDk,675
|
8
8
|
mm_std/env.py,sha256=5zaR9VeIfObN-4yfgxoFeU5IM1GDeZZj9SuYf7t9sOA,125
|
9
9
|
mm_std/fs.py,sha256=RwarNRJq3tIMG6LVX_g03hasfYpjYFh_O27oVDt5IPQ,291
|
10
10
|
mm_std/http_.py,sha256=QaPPXVb-rOS0BpoKdYQ0ABm_-mcR5dNa7Uqn-SeW_kE,4119
|
@@ -15,10 +15,10 @@ mm_std/print_.py,sha256=zB7sVbSSF8RffMxvnOdbKCXjCKtKzKV3R68pBri4NkQ,1638
|
|
15
15
|
mm_std/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
16
16
|
mm_std/random_.py,sha256=OuUX4VJeSd13NZBya4qrGpR2TfN7_87tfebOY6DBUnI,1113
|
17
17
|
mm_std/result.py,sha256=KLnPWjICYFkP6CAhq7Ifs22XSD-PQ9RkG6n1-cZcXkM,7625
|
18
|
-
mm_std/str.py,sha256=
|
18
|
+
mm_std/str.py,sha256=BEjJ1p5O4-uSYK0h-enasSSDdwzkBbiwdQ4_dsrlEE8,3257
|
19
19
|
mm_std/toml.py,sha256=CNznWKR0bpOxS6e3VB5LGS-Oa9lW-wterkcPUFtPcls,610
|
20
20
|
mm_std/types_.py,sha256=hvZlnvBWyB8CL_MeEWWD0Y0nN677plibYn3yD-5g7xs,99
|
21
21
|
mm_std/zip.py,sha256=axzF1BwcIygtfNNTefZH7hXKaQqwe-ZH3ChuRWr9dnk,396
|
22
|
-
mm_std-0.3.
|
23
|
-
mm_std-0.3.
|
24
|
-
mm_std-0.3.
|
22
|
+
mm_std-0.3.8.dist-info/METADATA,sha256=ORA3px7Ci92urZag-sz32QlEEDSwTuIQnjgt_eGTWwI,308
|
23
|
+
mm_std-0.3.8.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
24
|
+
mm_std-0.3.8.dist-info/RECORD,,
|
File without changes
|