We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3b82823 commit f8cb6b2Copy full SHA for f8cb6b2
src/tvm_book/utils.py
@@ -2,12 +2,18 @@ class Bunch(dict):
2
def __init__(self, *args, **kwargs):
3
super().__init__(*args, **kwargs)
4
self.__dict__ = self # 这意味着 Bunch 类的实例将具有与字典相同的行为,可以使用点符号访问和修改其键值对
5
+ self._convert_nested_dicts()
6
+
7
+ def _convert_nested_dicts(self):
8
for k, v in self.__dict__.items():
9
if isinstance(v, dict):
- self.__dict__[k] = Bunch(**v) # 支持嵌套结构
-
10
+ self.__dict__[k] = Bunch(**v) # 将字典转换为 Bunch 对象
11
+ elif isinstance(v, Bunch):
12
+ v._convert_nested_dicts() # 递归处理嵌套的 Bunch 对象
13
14
def merge(self, other):
15
"""提供递归合并功能"""
16
+ other = Bunch(**other)
17
for k, v in other.items():
18
if k not in self:
19
self[k] = other[k]
0 commit comments