forked from VimPlug/jedi
Rename next_sibling and prev_sibling.
This commit is contained in:
@@ -343,7 +343,7 @@ def _name_to_types(evaluator, name, scope):
|
|||||||
# TODO an exception can also be a tuple. Check for those.
|
# TODO an exception can also be a tuple. Check for those.
|
||||||
# TODO check for types that are not classes and add it to
|
# TODO check for types that are not classes and add it to
|
||||||
# the static analysis report.
|
# the static analysis report.
|
||||||
exceptions = evaluator.eval_element(name.prev_sibling().prev_sibling())
|
exceptions = evaluator.eval_element(name.get_previous_sibling().get_previous_sibling())
|
||||||
types = set(chain.from_iterable(evaluator.execute(t) for t in exceptions))
|
types = set(chain.from_iterable(evaluator.execute(t) for t in exceptions))
|
||||||
else:
|
else:
|
||||||
if typ.isinstance(er.Function):
|
if typ.isinstance(er.Function):
|
||||||
|
|||||||
@@ -162,8 +162,8 @@ class Instance(use_metaclass(CachedMetaClass, Executed)):
|
|||||||
sub = self._get_method_execution(sub)
|
sub = self._get_method_execution(sub)
|
||||||
for name_list in sub.names_dict.values():
|
for name_list in sub.names_dict.values():
|
||||||
for name in name_list:
|
for name in name_list:
|
||||||
if name.value == self_name and name.prev_sibling() is None:
|
if name.value == self_name and name.get_previous_sibling() is None:
|
||||||
trailer = name.next_sibling()
|
trailer = name.get_next_sibling()
|
||||||
if tree.is_node(trailer, 'trailer') \
|
if tree.is_node(trailer, 'trailer') \
|
||||||
and len(trailer.children) == 2 \
|
and len(trailer.children) == 2 \
|
||||||
and trailer.children[0] == '.':
|
and trailer.children[0] == '.':
|
||||||
|
|||||||
@@ -199,6 +199,32 @@ class Base(object):
|
|||||||
def nodes_to_execute(self, last_added=False):
|
def nodes_to_execute(self, last_added=False):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def get_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 get_previous_sibling(self):
|
||||||
|
"""
|
||||||
|
The node/leaf immediately preceding the invocant in their parent's
|
||||||
|
children list. If the invocant does not have a previous 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:
|
||||||
|
if i == 0:
|
||||||
|
return None
|
||||||
|
return self.parent.children[i - 1]
|
||||||
|
|
||||||
def get_previous_leaf(self):
|
def get_previous_leaf(self):
|
||||||
"""
|
"""
|
||||||
Returns the previous leaf in the parser tree.
|
Returns the previous leaf in the parser tree.
|
||||||
@@ -290,32 +316,6 @@ class Leaf(Base):
|
|||||||
else:
|
else:
|
||||||
return self.value
|
return 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 prev_sibling(self):
|
|
||||||
"""
|
|
||||||
The node/leaf immediately preceding the invocant in their parent's
|
|
||||||
children list. If the invocant does not have a previous 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:
|
|
||||||
if i == 0:
|
|
||||||
return None
|
|
||||||
return self.parent.children[i - 1]
|
|
||||||
|
|
||||||
def nodes_to_execute(self, last_added=False):
|
def nodes_to_execute(self, last_added=False):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@@ -383,7 +383,7 @@ class Name(Leaf):
|
|||||||
elif stmt.type == 'for_stmt':
|
elif stmt.type == 'for_stmt':
|
||||||
return self.start_pos < stmt.children[2].start_pos
|
return self.start_pos < stmt.children[2].start_pos
|
||||||
elif stmt.type == 'try_stmt':
|
elif stmt.type == 'try_stmt':
|
||||||
return self.prev_sibling() == 'as'
|
return self.get_previous_sibling() == 'as'
|
||||||
else:
|
else:
|
||||||
return stmt.type in ('expr_stmt', 'import_name', 'import_from',
|
return stmt.type in ('expr_stmt', 'import_name', 'import_from',
|
||||||
'comp_for', 'with_stmt') \
|
'comp_for', 'with_stmt') \
|
||||||
|
|||||||
Reference in New Issue
Block a user