Config Fix (#1267)

Added helper function to fix all() method
This commit is contained in:
Redjumpman 2018-01-28 21:19:41 -06:00 committed by Kowlin
parent 1b45397e67
commit 9feb7ad876

View File

@ -1,4 +1,5 @@
import logging import logging
import collections
from copy import deepcopy from copy import deepcopy
from typing import Callable, Union, Tuple from typing import Callable, Union, Tuple
@ -316,8 +317,24 @@ class Group(Value):
All of this Group's attributes, resolved as raw data values. All of this Group's attributes, resolved as raw data values.
""" """
defaults = self.defaults return self.nested_update(await self())
defaults.update(await self())
def nested_update(self, current, defaults=None):
"""Robust updater for nested dictionaries
If no defaults are passed, then the instance attribute 'defaults'
will be used.
"""
if not defaults:
defaults = deepcopy(self.defaults)
for key, value in current.items():
if isinstance(value, collections.Mapping):
result = self.nested_update(value, defaults.get(key, {}))
defaults[key] = result
else:
defaults[key] = deepcopy(current[key])
return defaults return defaults
async def set(self, value): async def set(self, value):