1
0
forked from VimPlug/jedi

Create a next_sibling method on _Leaf, which is then used to check for self attributes.

This commit is contained in:
Dave Halter
2014-10-23 01:36:24 +02:00
parent abb8d0e26c
commit 971f1db823
2 changed files with 19 additions and 18 deletions

View File

@@ -195,6 +195,19 @@ class _Leaf(Base):
def get_code(self):
return self.prefix + self.value
def next_sibling(self):
"""
The node immediately following the invocant in their parent's children
list. If the invocant does not have a next sibling, it is None
"""
# Can't use index(); we need to test by identity
for i, child in enumerate(self.parent.children):
if child is self:
try:
return self.parent.children[i + 1]
except IndexError:
return None
def __repr__(self):
return "<%s: %s>" % (type(self).__name__, repr(self.value))