dataconf 3.6.0__tar.gz → 3.7.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dataconf
3
- Version: 3.6.0
3
+ Version: 3.7.0
4
4
  Summary: Simple dataclasses configuration management for Python with hocon/json/yaml/properties/env-vars/dict support.
5
5
  Home-page: https://github.com/zifeo/dataconf
6
6
  License: MPL-2.0
@@ -45,13 +45,14 @@ class Multi:
45
45
  self.kwargs = kwargs
46
46
 
47
47
  def env(self, prefix: str, **kwargs) -> "Multi":
48
- self.strict = False
49
48
  data = env_vars_parse(prefix, os.environ)
50
- return self.dict(data, **kwargs)
49
+ strict = kwargs.pop("strict", False)
50
+ return self.dict(data, strict=strict, **kwargs)
51
51
 
52
52
  def dict(self, obj: Dict[str, Any], **kwargs) -> "Multi":
53
53
  conf = ConfigFactory.from_dict(obj)
54
- return Multi(self.confs + [conf], self.strict, **kwargs)
54
+ strict = kwargs.pop("strict", self.strict)
55
+ return Multi(self.confs + [conf], strict, **kwargs)
55
56
 
56
57
  def string(self, s: str, loader: str = HOCON, **kwargs) -> "Multi":
57
58
  if loader == YAML:
@@ -42,6 +42,21 @@ if PY310up:
42
42
 
43
43
  NoneType = type(None)
44
44
 
45
+ _BOOL_TRUE = {"true", "1", "yes", "on", "t", "y"}
46
+ _BOOL_FALSE = {"false", "0", "no", "off", "f", "n"}
47
+
48
+
49
+ def __parse_bool(value: Any):
50
+ if isinstance(value, bool):
51
+ return value
52
+ if isinstance(value, str):
53
+ normalised = value.strip().lower()
54
+ if normalised in _BOOL_TRUE:
55
+ return True
56
+ if normalised in _BOOL_FALSE:
57
+ return False
58
+ return None
59
+
45
60
 
46
61
  def __parse_type(value: Any, clazz: Type, path: str, check: bool):
47
62
  try:
@@ -208,14 +223,14 @@ def __parse(value: any, clazz: Type, path: str, strict: bool, ignore_unexpected:
208
223
  )
209
224
 
210
225
  if clazz is bool:
211
- if not strict and value is not None:
212
- try:
213
- value = bool(value)
214
- except ValueError:
215
- pass
216
- return __parse_type(value, clazz, path, isinstance(value, bool))
226
+ parsed = __parse_bool(value)
227
+ if parsed is not None:
228
+ return parsed
229
+ return __parse_type(value, clazz, path, False)
217
230
 
218
231
  if clazz is int:
232
+ if isinstance(value, bool):
233
+ return __parse_type(value, clazz, path, False)
219
234
  if not strict and value is not None:
220
235
  try:
221
236
  value = int(value)
@@ -224,6 +239,8 @@ def __parse(value: any, clazz: Type, path: str, strict: bool, ignore_unexpected:
224
239
  return __parse_type(value, clazz, path, isinstance(value, int))
225
240
 
226
241
  if clazz is float:
242
+ if isinstance(value, bool):
243
+ return __parse_type(value, clazz, path, False)
227
244
  if not strict and value is not None:
228
245
  try:
229
246
  value = float(value)
@@ -243,7 +260,7 @@ def __parse(value: any, clazz: Type, path: str, strict: bool, ignore_unexpected:
243
260
  return value
244
261
 
245
262
  if isclass(clazz) and (issubclass(clazz, Enum) or issubclass(clazz, IntEnum)):
246
- if isinstance(value, int):
263
+ if isinstance(value, int) and not isinstance(value, bool):
247
264
  return clazz.__call__(value)
248
265
  elif issubclass(clazz, str):
249
266
  return clazz(value)
@@ -1,6 +1,6 @@
1
1
  import sys
2
2
 
3
- __version__ = "3.6.0"
3
+ __version__ = "3.7.0"
4
4
 
5
5
  PY310up = sys.version_info >= (3, 10)
6
6
  PY311up = sys.version_info >= (3, 11)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "dataconf"
3
- version = "3.6.0"
3
+ version = "3.7.0"
4
4
  description = "Simple dataclasses configuration management for Python with hocon/json/yaml/properties/env-vars/dict support."
5
5
  authors = []
6
6
  license = "MPL-2.0"
@@ -48,7 +48,7 @@ ruff = ">=0.12.7"
48
48
 
49
49
  [tool.commitizen]
50
50
  name = "cz_conventional_commits"
51
- version = "3.6.0"
51
+ version = "3.7.0"
52
52
  tag_format = "v$major.$minor.$patch$prerelease"
53
53
  version_files = [
54
54
  "pyproject.toml:version",
File without changes
File without changes
File without changes
File without changes
File without changes