Skip to content

Commit

Permalink
tree.pyx: t.remove_child() allows to pass a name instead of a node.
Browse files Browse the repository at this point in the history
  • Loading branch information
jordibc committed Nov 12, 2023
1 parent 9d26e5c commit f936513
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ete4/core/tree.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,16 @@ cdef class Tree(object):
but are no longer connected.
"""
try:
if type(child) == str: # translate into a node
child = next(n for n in self.children if n.name == child)

self.children.remove(child) # parent removes child

if child.up == self: # (it may point to another already!)
child.up = None # child removes parent

return child
except ValueError as e:
except (StopIteration, ValueError) as e:
raise TreeError(f'Cannot remove child: not found ({e})')

def remove_children(self):
Expand Down

0 comments on commit f936513

Please sign in to comment.