diff --git a/jedi/evaluate/representation.py b/jedi/evaluate/representation.py index 0eb5be6d..b4fa36f0 100644 --- a/jedi/evaluate/representation.py +++ b/jedi/evaluate/representation.py @@ -136,16 +136,6 @@ class Instance(use_metaclass(CachedMetaClass, Executed)): @memoize_default([]) def get_self_attributes(self): - def add_self_dot_name(name): - """ - Need to copy and rewrite the name, because names are now - ``instance_usage.variable`` instead of ``self.variable``. - """ - n = copy.copy(name) - n.names = n.names[1:] - n._get_code = unicode(n.names[-1]) - names.append(get_instance_el(self._evaluator, self, n)) - names = [] # This loop adds the names of the self object, copies them and removes # the self. @@ -166,14 +156,12 @@ class Instance(use_metaclass(CachedMetaClass, Executed)): # complicated. sub = self._get_method_execution(sub) print(sub.names_dict.values()) - for per_name_list in sub.names_dict.values(): - for call in per_name_list: - if name.value == self_name \ - and isinstance(call.next, pr.Call) \ - and call.next.next is None: - names.append(get_instance_el(self._evaluator, self, call.next.name)) - #if unicode(n.names[0]) == self_name and len(n.names) == 2: - # add_self_dot_name(n) + for name_list in sub.names_dict.values(): + for name in name_list: + if name.value == self_name: + next = name.next_sibling() + if isinstance(next, pr.Name) and next.is_definition(): + names.append(get_instance_el(self._evaluator, self, next)) for s in self.base.py__bases__(self._evaluator): if not isinstance(s, compiled.CompiledObject): diff --git a/jedi/parser/representation.py b/jedi/parser/representation.py index 8e33b154..f5ef8e09 100644 --- a/jedi/parser/representation.py +++ b/jedi/parser/representation.py @@ -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))