From 9feb7ad876840540c4e1f660e443b74c5bb68d12 Mon Sep 17 00:00:00 2001 From: Redjumpman Date: Sun, 28 Jan 2018 21:19:41 -0600 Subject: [PATCH] Config Fix (#1267) Added helper function to fix all() method --- redbot/core/config.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/redbot/core/config.py b/redbot/core/config.py index ac22dac37..791a32903 100644 --- a/redbot/core/config.py +++ b/redbot/core/config.py @@ -1,4 +1,5 @@ import logging +import collections from copy import deepcopy from typing import Callable, Union, Tuple @@ -316,8 +317,24 @@ class Group(Value): All of this Group's attributes, resolved as raw data values. """ - defaults = self.defaults - defaults.update(await self()) + return self.nested_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 async def set(self, value):