Skip to content

Commit

Permalink
Version 3.4.5 (#106)
Browse files Browse the repository at this point in the history
* Fixing issue with update not converting properly (thanks to Michael Stella)
* Changing back to old update merge method
  • Loading branch information
cdgriffith committed Sep 28, 2019
1 parent 1a63d7b commit f113d15
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ Suggestions and bug reporting:
- Nikolay Stanishev (nikolaystanishev)
- Craig Quiter (crizCraig)
- Jeremiah Lowin (jlowin)
- Michael Stella (alertedsnake)
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
---------

Version 3.4.5
~~~~~~~~~~~~~

* Fixing update does not convert new sub dictionaries or lists (thanks to Michael Stella)
* Changing update to work as it used to with sub merging until major release

Version 3.4.4
~~~~~~~~~~~~~

Expand Down
30 changes: 20 additions & 10 deletions box.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
__all__ = ['Box', 'ConfigBox', 'BoxList', 'SBox',
'BoxError', 'BoxKeyError']
__author__ = 'Chris Griffith'
__version__ = '3.4.4'
__version__ = '3.4.5'

BOX_PARAMETERS = ('default_box', 'default_box_attr', 'conversion_box',
'frozen_box', 'camel_killer_box', 'box_it_up',
Expand Down Expand Up @@ -648,15 +648,25 @@ def to_dict(self):
return out_dict

def update(self, E=None, **F):
if E:
if hasattr(E, 'keys'):
for k in E:
self[k] = self.__convert_and_store(k, E[k])
else:
for k, v in E:
self[k] = self.__convert_and_store(k, v)
for k in F:
self[k] = self.__convert_and_store(k, F[k])
if not E:
E = F
iter_over = E.items() if hasattr(E, 'items') else E
for k, v in iter_over:
intact_type = (self._box_config['box_intact_types'] and
isinstance(v, self._box_config['box_intact_types']))
if isinstance(v, dict) and not intact_type:
# Box objects must be created in case they are already
# in the `converted` box_config set
v = self.__class__(v, **self.__box_config())
if k in self and isinstance(self[k], dict):
self[k].update(v)
continue
if isinstance(v, list) and not intact_type:
v = BoxList(v, **self.__box_config())
try:
self.__setattr__(k, v)
except (AttributeError, TypeError):
self.__setitem__(k, v)

def setdefault(self, item, default=None):
if item in self:
Expand Down
10 changes: 8 additions & 2 deletions test/test_functional_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,23 @@ def test_update(self):
'lister': ['a']})
a.update([('asdf', 'fdsa')])
a.update(testkey=66)
a.update({'items': 'test'})
a.update({'items': {'test': 'pme'}})
a.update({'key1': {'gg': 4}})
b = Box()
b.update(item=1)

assert a.grand == 1000
assert a['grand'] == 1000
assert a['items'] == 'test'
assert isinstance(a['items'], Box)
assert a['items'].test == 'pme'
assert a.key1.new == 5
assert a['Key 2'].add_key == 6
assert isinstance(a.key1, Box)
assert isinstance(a.lister, BoxList)
assert a.asdf == 'fdsa'
assert a.testkey == 66
assert a.key1.new == 5 # On regular dict update this shouldn't happen
assert a.key1.gg == 4

c = Box(box_intact_types=[list])
c.a = [1, 2]
Expand Down

0 comments on commit f113d15

Please sign in to comment.