forked from VimPlug/jedi
simplify a lot of the current InstanceElement behavior, because we know now, that there's either a Statement or a Function inside (or maybe some other parser objects like an Array.
This commit is contained in:
@@ -198,7 +198,8 @@ def get_instance_el(evaluator, instance, var, is_class_var=False):
|
|||||||
Returns an InstanceElement if it makes sense, otherwise leaves the object
|
Returns an InstanceElement if it makes sense, otherwise leaves the object
|
||||||
untouched.
|
untouched.
|
||||||
"""
|
"""
|
||||||
if isinstance(var, (Instance, compiled.CompiledObject)):
|
if isinstance(var, (Instance, compiled.CompiledObject, pr.Operator, Token,
|
||||||
|
pr.Module)):
|
||||||
return var
|
return var
|
||||||
|
|
||||||
if isinstance(var, pr.Function):
|
if isinstance(var, pr.Function):
|
||||||
@@ -228,8 +229,9 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)):
|
|||||||
or isinstance(par, pr.Class) \
|
or isinstance(par, pr.Class) \
|
||||||
and par == self.instance.base.base:
|
and par == self.instance.base.base:
|
||||||
par = self.instance
|
par = self.instance
|
||||||
elif not isinstance(par, (pr.Module, compiled.CompiledObject)):
|
else:
|
||||||
par = get_instance_el(self.instance._evaluator, self.instance, par, self.is_class_var)
|
par = get_instance_el(self._evaluator, self.instance, par,
|
||||||
|
self.is_class_var)
|
||||||
return par
|
return par
|
||||||
|
|
||||||
def get_parent_until(self, *args, **kwargs):
|
def get_parent_until(self, *args, **kwargs):
|
||||||
@@ -244,12 +246,11 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)):
|
|||||||
def expression_list(self):
|
def expression_list(self):
|
||||||
# Copy and modify the array.
|
# Copy and modify the array.
|
||||||
return [get_instance_el(self._evaluator, self.instance, command, self.is_class_var)
|
return [get_instance_el(self._evaluator, self.instance, command, self.is_class_var)
|
||||||
if not isinstance(command, (pr.Operator, Token)) else command
|
|
||||||
for command in self.var.expression_list()]
|
for command in self.var.expression_list()]
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for el in self.var.__iter__():
|
for el in self.var.__iter__():
|
||||||
yield get_instance_el(self.instance._evaluator, self.instance, el,
|
yield get_instance_el(self._evaluator, self.instance, el,
|
||||||
self.is_class_var)
|
self.is_class_var)
|
||||||
|
|
||||||
def __getitem__(self, index):
|
def __getitem__(self, index):
|
||||||
@@ -263,16 +264,7 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)):
|
|||||||
return isinstance(self.var, cls)
|
return isinstance(self.var, cls)
|
||||||
|
|
||||||
def py__call__(self, evaluator, params):
|
def py__call__(self, evaluator, params):
|
||||||
# TODO Why is CompiledObject even an InstanceObject?
|
return Function.py__call__(self, evaluator, params)
|
||||||
if isinstance(self.var, (compiled.CompiledObject, Instance)):
|
|
||||||
try:
|
|
||||||
func = self.var.py__call__
|
|
||||||
except AttributeError:
|
|
||||||
return []
|
|
||||||
else:
|
|
||||||
return func(evaluator, params)
|
|
||||||
else:
|
|
||||||
return Function.py__call__(self, evaluator, params)
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s of %s>" % (type(self).__name__, self.var)
|
return "<%s of %s>" % (type(self).__name__, self.var)
|
||||||
|
|||||||
Reference in New Issue
Block a user