Skip to content

Commit

Permalink
fix #209, improve doc (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
c0fec0de authored Oct 11, 2023
1 parent ac79240 commit 518174e
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions anytree/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def commonancestors(*nodes):
"""
Determine common ancestors of `nodes`.
>>> from anytree import Node
>>> from anytree import Node, util
>>> udo = Node("Udo")
>>> marc = Node("Marc", parent=udo)
>>> lian = Node("Lian", parent=marc)
Expand All @@ -14,13 +14,13 @@ def commonancestors(*nodes):
>>> jan = Node("Jan", parent=dan)
>>> joe = Node("Joe", parent=dan)
>>> commonancestors(jet, joe)
>>> util.commonancestors(jet, joe)
(Node('/Udo'), Node('/Udo/Dan'))
>>> commonancestors(jet, marc)
>>> util.commonancestors(jet, marc)
(Node('/Udo'),)
>>> commonancestors(jet)
>>> util.commonancestors(jet)
(Node('/Udo'), Node('/Udo/Dan'))
>>> commonancestors()
>>> util.commonancestors()
()
"""
ancestors = [node.ancestors for node in nodes]
Expand All @@ -38,16 +38,18 @@ def leftsibling(node):
"""
Return Left Sibling of `node`.
>>> from anytree import Node
>>> from anytree import Node, util
>>> dan = Node("Dan")
>>> jet = Node("Jet", parent=dan)
>>> jan = Node("Jan", parent=dan)
>>> joe = Node("Joe", parent=dan)
>>> leftsibling(dan)
>>> leftsibling(jet)
>>> leftsibling(jan)
>>> print(util.leftsibling(dan))
None
>>> print(util.leftsibling(jet))
None
>>> print(util.leftsibling(jan))
Node('/Dan/Jet')
>>> leftsibling(joe)
>>> print(util.leftsibling(joe))
Node('/Dan/Jan')
"""
if node.parent:
Expand All @@ -62,17 +64,19 @@ def rightsibling(node):
"""
Return Right Sibling of `node`.
>>> from anytree import Node
>>> from anytree import Node, util
>>> dan = Node("Dan")
>>> jet = Node("Jet", parent=dan)
>>> jan = Node("Jan", parent=dan)
>>> joe = Node("Joe", parent=dan)
>>> rightsibling(dan)
>>> rightsibling(jet)
>>> print(util.rightsibling(dan))
None
>>> print(util.rightsibling(jet))
Node('/Dan/Jan')
>>> rightsibling(jan)
>>> print(util.rightsibling(jan))
Node('/Dan/Joe')
>>> rightsibling(joe)
>>> print(util.rightsibling(joe))
None
"""
if node.parent:
pchildren = node.parent.children
Expand Down

0 comments on commit 518174e

Please sign in to comment.