浏览代码

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

PropDict: fail early if internal_dict is not a dict
TW 4 年之前
父节点
当前提交
1f3a91f72f
共有 1 个文件被更改,包括 12 次插入6 次删除
  1. 12 6
      src/borg/item.pyx

+ 12 - 6
src/borg/item.pyx

@@ -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():