forked from VimPlug/jedi
Adding prev_sibling, getting self attributes.
This commit is contained in:
@@ -295,11 +295,16 @@ class FakeArray(pr.Array):
|
|||||||
|
|
||||||
class FakeStatement(pr.ExprStmt):
|
class FakeStatement(pr.ExprStmt):
|
||||||
def __init__(self, values, start_pos=(0, 0), parent=None):
|
def __init__(self, values, start_pos=(0, 0), parent=None):
|
||||||
p = start_pos
|
self._start_pos = start_pos
|
||||||
super(FakeStatement, self).__init__([])
|
super(FakeStatement, self).__init__([])
|
||||||
self.values = values
|
self.values = values
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
|
||||||
|
@property
|
||||||
|
def start_pos(self):
|
||||||
|
"""Overwriting the original start_pos property."""
|
||||||
|
return self._start_pos
|
||||||
|
|
||||||
|
|
||||||
class FakeImport(pr.Import):
|
class FakeImport(pr.Import):
|
||||||
def __init__(self, name, parent, level=0):
|
def __init__(self, name, parent, level=0):
|
||||||
|
|||||||
@@ -394,6 +394,7 @@ def _gen_param_name_copy(func, var_args, param, keys=(), values=(), array_type=N
|
|||||||
"""
|
"""
|
||||||
Create a param with the original scope (of varargs) as parent.
|
Create a param with the original scope (of varargs) as parent.
|
||||||
"""
|
"""
|
||||||
|
print(func, var_args, param, keys, values, array_type)
|
||||||
if isinstance(var_args, pr.Array):
|
if isinstance(var_args, pr.Array):
|
||||||
parent = var_args.parent
|
parent = var_args.parent
|
||||||
start_pos = var_args.start_pos
|
start_pos = var_args.start_pos
|
||||||
|
|||||||
@@ -155,13 +155,14 @@ class Instance(use_metaclass(CachedMetaClass, Executed)):
|
|||||||
# because to follow them and their self variables is too
|
# because to follow them and their self variables is too
|
||||||
# complicated.
|
# complicated.
|
||||||
sub = self._get_method_execution(sub)
|
sub = self._get_method_execution(sub)
|
||||||
print(sub.names_dict.values())
|
|
||||||
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:
|
if name.value == self_name and name.prev_sibling() is None:
|
||||||
next = name.next_sibling()
|
trailer = name.next_sibling()
|
||||||
if isinstance(next, pr.Name) and next.is_definition():
|
if pr.is_node(trailer, 'trailer') \
|
||||||
names.append(get_instance_el(self._evaluator, self, next))
|
and len(trailer.children) == 2:
|
||||||
|
name = trailer.children[1] # After dot.
|
||||||
|
names.append(get_instance_el(self._evaluator, self, name))
|
||||||
|
|
||||||
for s in self.base.py__bases__(self._evaluator):
|
for s in self.base.py__bases__(self._evaluator):
|
||||||
if not isinstance(s, compiled.CompiledObject):
|
if not isinstance(s, compiled.CompiledObject):
|
||||||
|
|||||||
@@ -208,6 +208,18 @@ class _Leaf(Base):
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def prev_sibling(self):
|
||||||
|
"""
|
||||||
|
The node 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 __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s: %s>" % (type(self).__name__, repr(self.value))
|
return "<%s: %s>" % (type(self).__name__, repr(self.value))
|
||||||
|
|
||||||
@@ -1249,6 +1261,10 @@ class Param(object):
|
|||||||
annotation_stmt.parent = self.use_as_parent
|
annotation_stmt.parent = self.use_as_parent
|
||||||
self.annotation_stmt = annotation_stmt
|
self.annotation_stmt = annotation_stmt
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
default = '' if self.default is None else '=%s' % self.default
|
||||||
|
return '<%s: %s>' % (type(self).__name__, str(self.tfpdef) + default)
|
||||||
|
|
||||||
|
|
||||||
class StatementElement(Simple):
|
class StatementElement(Simple):
|
||||||
__slots__ = ('next', 'previous')
|
__slots__ = ('next', 'previous')
|
||||||
|
|||||||
Reference in New Issue
Block a user