mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +08:00
InstanceElement cleanup, not all tests pass, though
This commit is contained in:
23
evaluate.py
23
evaluate.py
@@ -269,22 +269,24 @@ class InstanceElement(use_metaclass(CachedMetaClass)):
|
|||||||
def __init__(self, instance, var):
|
def __init__(self, instance, var):
|
||||||
if isinstance(var, parsing.Function):
|
if isinstance(var, parsing.Function):
|
||||||
var = Function(var)
|
var = Function(var)
|
||||||
|
elif isinstance(var, parsing.Class):
|
||||||
|
var = Class(var)
|
||||||
self.instance = instance
|
self.instance = instance
|
||||||
self.var = var
|
self.var = var
|
||||||
|
|
||||||
@memoize_default()
|
@memoize_default()
|
||||||
def parent(self):
|
def parent(self):
|
||||||
par = self.var.parent()
|
par = self.var.parent()
|
||||||
if not isinstance(par, (parsing.Module, Class)):
|
if isinstance(par, Class) and par == self.instance.base \
|
||||||
|
or isinstance(par, parsing.Class) \
|
||||||
|
and par == self.instance.base.base:
|
||||||
|
par = self.instance
|
||||||
|
elif not isinstance(par, parsing.Module):
|
||||||
par = InstanceElement(self.instance, par)
|
par = InstanceElement(self.instance, par)
|
||||||
return par
|
return par
|
||||||
|
|
||||||
def get_parent_until(self, *classes):
|
def get_parent_until(self, *classes):
|
||||||
scope = self.var.get_parent_until(*classes)
|
return parsing.Simple.get_parent_until(self, *classes)
|
||||||
if isinstance(scope, parsing.Module):
|
|
||||||
return scope
|
|
||||||
else:
|
|
||||||
return InstanceElement(self.instance, scope)
|
|
||||||
|
|
||||||
def get_decorated_func(self):
|
def get_decorated_func(self):
|
||||||
""" Needed because the InstanceElement should not be stripped """
|
""" Needed because the InstanceElement should not be stripped """
|
||||||
@@ -880,13 +882,13 @@ def get_names_for_scope(scope, position=None, star_search=True,
|
|||||||
# Ignore the Flows, because the classes and functions care for that.
|
# Ignore the Flows, because the classes and functions care for that.
|
||||||
# InstanceElement of Class is ignored, if it is not the start scope.
|
# InstanceElement of Class is ignored, if it is not the start scope.
|
||||||
if not (scope != start_scope and scope.isinstance(parsing.Class)
|
if not (scope != start_scope and scope.isinstance(parsing.Class)
|
||||||
or isinstance(scope, parsing.Flow)):
|
or scope.isinstance(parsing.Flow)):
|
||||||
try:
|
try:
|
||||||
yield scope, get_defined_names_for_position(scope, position,
|
yield scope, get_defined_names_for_position(scope, position,
|
||||||
in_scope)
|
in_scope)
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
raise MultiLevelStopIteration('StopIteration raised somewhere')
|
raise MultiLevelStopIteration('StopIteration raised somewhere')
|
||||||
if isinstance(scope, parsing.ForFlow) and scope.is_list_comp:
|
if scope.isinstance(parsing.ForFlow) and scope.is_list_comp:
|
||||||
yield scope, scope.get_set_vars(is_internal_call=True)
|
yield scope, scope.get_set_vars(is_internal_call=True)
|
||||||
|
|
||||||
scope = scope.parent()
|
scope = scope.parent()
|
||||||
@@ -989,9 +991,6 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False):
|
|||||||
"""
|
"""
|
||||||
result = []
|
result = []
|
||||||
no_break_scope = False
|
no_break_scope = False
|
||||||
if isinstance(scope, InstanceElement) \
|
|
||||||
and scope.var == name.parent().parent():
|
|
||||||
name = InstanceElement(scope.instance, name)
|
|
||||||
par = name.parent()
|
par = name.parent()
|
||||||
|
|
||||||
if par.isinstance(parsing.Flow):
|
if par.isinstance(parsing.Flow):
|
||||||
@@ -1036,11 +1035,13 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False):
|
|||||||
details = par.assignment_details
|
details = par.assignment_details
|
||||||
if details and details[0][0] != '=':
|
if details and details[0][0] != '=':
|
||||||
no_break_scope = True
|
no_break_scope = True
|
||||||
|
|
||||||
# TODO this makes self variables non-breakable. wanted?
|
# TODO this makes self variables non-breakable. wanted?
|
||||||
r = [n for n in par.get_set_vars()
|
r = [n for n in par.get_set_vars()
|
||||||
if len(n) > 1 and str(n.names[-1] == name)]
|
if len(n) > 1 and str(n.names[-1] == name)]
|
||||||
if isinstance(name, InstanceElement) and r:
|
if isinstance(name, InstanceElement) and r:
|
||||||
no_break_scope = True
|
no_break_scope = True
|
||||||
|
|
||||||
result.append(par)
|
result.append(par)
|
||||||
else:
|
else:
|
||||||
result.append(par)
|
result.append(par)
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ class Simple(Base):
|
|||||||
self.end_pos = end_pos
|
self.end_pos = end_pos
|
||||||
self.parent = lambda: None
|
self.parent = lambda: None
|
||||||
|
|
||||||
|
@Python3Method
|
||||||
def get_parent_until(self, *classes):
|
def get_parent_until(self, *classes):
|
||||||
""" Takes always the parent, until one class (not a Class) """
|
""" Takes always the parent, until one class (not a Class) """
|
||||||
scope = self
|
scope = self
|
||||||
|
|||||||
@@ -181,7 +181,8 @@ class V:
|
|||||||
|
|
||||||
d = b
|
d = b
|
||||||
b = ret
|
b = ret
|
||||||
c = b
|
if 1:
|
||||||
|
c = b
|
||||||
|
|
||||||
#? int()
|
#? int()
|
||||||
V(1).b()
|
V(1).b()
|
||||||
|
|||||||
Reference in New Issue
Block a user