python-bunch 0.1.6__py3-none-any.whl → 0.1.7__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.
bunch/bunch.py CHANGED
@@ -66,5 +66,19 @@ class Bunch:
66
66
  return self.__dict__.items()
67
67
 
68
68
  @staticmethod
69
- def from_dict(dictionary: dict) -> Any:
70
- return Bunch(**dictionary)
69
+ def from_dict(dictionary: dict, recursive: bool = True) -> 'Bunch':
70
+ ret = Bunch()
71
+ if recursive:
72
+ for key, value in dictionary.items():
73
+ if isinstance(value, dict):
74
+ ret[key] = Bunch.from_dict(value, recursive=True)
75
+ elif isinstance(value, list):
76
+ ret[key] = [
77
+ Bunch.from_dict(item, recursive=True) if isinstance(item, dict) else item
78
+ for item in value
79
+ ]
80
+ else:
81
+ ret[key] = value
82
+ else:
83
+ ret.update(dictionary)
84
+ return ret
bunch/immutable_bunch.py CHANGED
@@ -1,6 +1,6 @@
1
1
  import json
2
2
  from typing import Any
3
-
3
+ from bunch.bunch import Bunch
4
4
 
5
5
  class ImmutableBunchException(Exception):
6
6
  def __init__(self, message: str) -> None:
@@ -71,5 +71,19 @@ class ImmutableBunch:
71
71
  return self.__dict__.items()
72
72
 
73
73
  @staticmethod
74
- def from_dict(dictionary: dict) -> Any:
75
- return ImmutableBunch(**dictionary)
74
+ def from_dict(dictionary: dict, recursive: bool = True) -> 'ImmutableBunch':
75
+ ret = dict()
76
+ if recursive:
77
+ for key, value in dictionary.items():
78
+ if isinstance(value, dict):
79
+ ret[key] = ImmutableBunch.from_dict(value, recursive=True)
80
+ elif isinstance(value, list):
81
+ ret[key] = [
82
+ ImmutableBunch.from_dict(item, recursive=True) if isinstance(item, dict) else item
83
+ for item in value
84
+ ]
85
+ else:
86
+ ret[key] = value
87
+ else:
88
+ ret.update(dictionary)
89
+ return ImmutableBunch(**ret)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-bunch
3
- Version: 0.1.6
3
+ Version: 0.1.7
4
4
  Summary: A lightweight Python class that behaves like a dict but supports attribute-style access.
5
5
  Author-email: Omer Menashe <unspecified@mail.com>
6
6
  License: MIT
@@ -0,0 +1,8 @@
1
+ bunch/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ bunch/bunch.py,sha256=2McoGdOxW2DCmM4ysMKBsrzsVSG335x9sbrWYREb7Q8,2528
3
+ bunch/immutable_bunch.py,sha256=8xRbuR-Rwo0o7DieldF6rsXd8GyHAz95xfSkisfdw_A,3169
4
+ python_bunch-0.1.7.dist-info/licenses/LICENSE,sha256=pd5qyxFyPdg1u_AlxsTrh9RF1Ys0AH8sM3C0HTC9EgY,1057
5
+ python_bunch-0.1.7.dist-info/METADATA,sha256=HRIQLCZxomfc2_aSiZtQadsbm4PRpbYimf5vHZBk9Vg,1828
6
+ python_bunch-0.1.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
+ python_bunch-0.1.7.dist-info/top_level.txt,sha256=A1w3sDjR8t1mZ4GDuhD9afxgybqy6nHJHPA4CbrgFRA,6
8
+ python_bunch-0.1.7.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.4.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,8 +0,0 @@
1
- bunch/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- bunch/bunch.py,sha256=seTk3I_dKKAmVcMHTTUZUWXZYkPQYV_aStgl2eN0V-I,1945
3
- bunch/immutable_bunch.py,sha256=SIGHf0HSfJbddEr8wfVK3mB-qSnaO1_rz--VQKcr5Cc,2522
4
- python_bunch-0.1.6.dist-info/licenses/LICENSE,sha256=pd5qyxFyPdg1u_AlxsTrh9RF1Ys0AH8sM3C0HTC9EgY,1057
5
- python_bunch-0.1.6.dist-info/METADATA,sha256=FZyX2weuuFpOgY3z7rZSG19njP3aRsJ4bbijlc997H4,1828
6
- python_bunch-0.1.6.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
7
- python_bunch-0.1.6.dist-info/top_level.txt,sha256=A1w3sDjR8t1mZ4GDuhD9afxgybqy6nHJHPA4CbrgFRA,6
8
- python_bunch-0.1.6.dist-info/RECORD,,