Merge pull request #5496 from ThomasWaldmann/item-assert-dict

PropDict: fail early if internal_dict is not a dict
This commit is contained in:
TW 2020-11-15 15:38:03 +01:00 committed by GitHub
commit 1f3a91f72f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 6 deletions

View File

@ -40,15 +40,21 @@ class PropDict:
__slots__ = ("_dict", ) # avoid setting attributes not supported by properties
def __init__(self, data_dict=None, internal_dict=None, **kw):
self._dict = {}
if internal_dict is None:
pass # nothing to do
elif isinstance(internal_dict, dict):
self.update_internal(internal_dict)
else:
raise TypeError("internal_dict must be a dict")
if data_dict is None:
data = kw
elif not isinstance(data_dict, dict):
raise TypeError("data_dict must be dict")
else:
elif isinstance(data_dict, dict):
data = data_dict
self._dict = {}
self.update_internal(internal_dict or {})
self.update(data)
else:
raise TypeError("data_dict must be a dict")
if data:
self.update(data)
def update(self, d):
for k, v in d.items():