Ensure a node has no children before populating it

I'm struggling to recreate https://github.com/Textualize/frogmouth/issues/50
in a controlled way, but reviewing the code here makes me think that this is
a good idea anyway. While DirectoryTree should not end up in _populate_node
if a node has already been populated, it's also the case that it's an
all-or-nothing thing; it makes sense to clear out the children of the node
before populating it; at least in a belt-and-braces way.
This commit is contained in:
Dave Pearson
2023-05-25 20:49:50 +01:00
parent 20d19d977d
commit 32790de26a

View File

@@ -271,6 +271,7 @@ class DirectoryTree(Tree[DirEntry]):
node: The Tree node to populate.
content: The collection of `Path` objects to populate the node with.
"""
node.remove_children()
for path in content:
node.add(
path.name,