提交 2ad248f3 编写于 作者: HansBug's avatar HansBug 😆

dev(hansbug): update the default value of include_nodes from False to True

上级 c803ab42
......@@ -623,7 +623,7 @@ def get_tree_test(tree_value_clazz: Type[TreeValue]):
def test_walk(self):
tv1 = tree_value_clazz({'a': 1, 'b': 'dks', 'c': {'x': 2, 'y': 3}})
for p, v in tv1.walk():
for p, v in tv1.walk(include_nodes=False):
if p == ('a',):
assert v == 1
elif p == ('b',):
......@@ -635,7 +635,7 @@ def get_tree_test(tree_value_clazz: Type[TreeValue]):
else:
pytest.fail('Should not reach here - %s is accessed.' % (repr(p),))
for p, v in tv1.walk(include_nodes=True):
for p, v in tv1.walk():
if p == ():
assert v == tv1
elif p == ('a',):
......
......@@ -105,9 +105,17 @@ class TestTreeTreeService:
tv1 = MyTreeValue({'a': 1, 'b': 2, 'c': {'x': 2, 'y': 3}})
assert dict(walk(tv1, include_nodes=False)) == {
('a',): 1,
('b',): 2,
('c', 'x',): 2,
('c', 'y',): 3,
}
assert dict(walk(tv1)) == {
(): MyTreeValue({'a': 1, 'b': 2, 'c': {'x': 2, 'y': 3}}),
('a',): 1,
('b',): 2,
('c',): MyTreeValue({'x': 2, 'y': 3}),
('c', 'x',): 2,
('c', 'y',): 3,
}
......@@ -126,8 +134,10 @@ class TestTreeTreeService:
'c': delayed(lambda: tv1.c),
})
assert dict(walk(tv2)) == {
(): MyTreeValue({'a': 1, 'b': 2, 'c': {'x': 2, 'y': 3}}),
('a',): 1,
('b',): 2,
('c',): MyTreeValue({'x': 2, 'y': 3}),
('c', 'x',): 2,
('c', 'y',): 3,
}
......@@ -210,7 +210,7 @@ def general_tree_value(base: Optional[Mapping[str, Any]] = None,
return filter_(self, func, remove_empty)
@_decorate_method
def walk(self, include_nodes: bool = False):
def walk(self, include_nodes: bool = True):
"""
Overview:
Walk the values and nodes in the tree.
......
......@@ -106,7 +106,7 @@ def _p_walk(TreeStorage tree, object type_, tuple path, bool include_nodes):
yield curpath, v
@cython.binding(True)
cpdef walk(TreeValue tree, bool include_nodes=False):
cpdef walk(TreeValue tree, bool include_nodes=True):
"""
Overview:
Walk the values and nodes in the tree.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册