thaw_frozendict should be fully recursive

So far it was only deep-diving into frozendicts, not dicts (which might
contain frozendicts).

In principle we probably should also dive into tuples and lists and
other containers, but in our current application we don't put
frozendicts into those so let's not overdo it.
This commit is contained in:
Gina Häußge committed 2018-04-03 16:56:59 +02:00
1 parent c1fe8f5a35
commit 9f80aefcc9
2 files changed
+2 -1

No files matched your search

+1 -1
View File
@@ -979,7 +979,7 @@ def thaw_frozendict(obj):
# only true love can thaw a frozen dict
letitgo = dict()
for key, value in obj.items():
if isinstance(value, frozendict.frozendict):
if isinstance(value, (dict, frozendict.frozendict)):
letitgo[key] = thaw_frozendict(value)
else:
letitgo[key] = copy.deepcopy(value)
+1
View File
@@ -52,6 +52,7 @@ class MiscTestCase(unittest.TestCase):
(frozendict(a=1, b=2, c=frozendict(c1=1, c2=2)), dict(a=1, b=2, c=dict(c1=1, c2=2))),
(dict(a=1, b=2, c=3), dict(a=1, b=2, c=3)),
(dict(a=1, b=2, c=frozendict(c1=1, c2=2)), dict(a=1, b=2, c=dict(c1=1, c2=2))),
(dict(a=1, b=2, c=dict(c1=1, c2=2, c3=frozendict(c11=11, c12=12))), dict(a=1, b=2, c=dict(c1=1, c2=2, c3=dict(c11=11, c12=12))))
)
@ddt.unpack
def test_unfreeze_frozendict(self, input, expected):