forked from VimPlug/jedi
fix most issues related to the py__call__ stuff and generalize it.
This commit is contained in:
@@ -325,24 +325,24 @@ class Evaluator(object):
|
||||
pass
|
||||
|
||||
if isinstance(obj, iterable.GeneratorMethod):
|
||||
return obj.py__call__(params)
|
||||
return obj.py__call__(self, params)
|
||||
elif obj.isinstance(compiled.CompiledObject):
|
||||
return obj.py__call__(self, params)
|
||||
elif obj.isinstance(er.Class):
|
||||
# There maybe executions of executions.
|
||||
return obj.py__call__(params)
|
||||
return obj.py__call__(self, params)
|
||||
else:
|
||||
stmts = []
|
||||
if obj.isinstance(er.Function):
|
||||
return obj.py__call__(params, evaluate_generator)
|
||||
return obj.py__call__(self, params, evaluate_generator)
|
||||
else:
|
||||
if hasattr(obj, 'execute_subscope_by_name'):
|
||||
try:
|
||||
stmts = obj.execute_subscope_by_name('__call__', params)
|
||||
except KeyError:
|
||||
debug.warning("no __call__ func available %s", obj)
|
||||
else:
|
||||
try:
|
||||
func = obj.py__call__
|
||||
except AttributeError:
|
||||
debug.warning("no execution possible %s", obj)
|
||||
return []
|
||||
else:
|
||||
return func(self, params)
|
||||
|
||||
debug.dbg('execute result: %s in %s', stmts, obj)
|
||||
return imports.follow_imports(self, stmts)
|
||||
|
||||
@@ -94,7 +94,7 @@ class GeneratorMethod(object):
|
||||
self._builtin_func = builtin_func
|
||||
self._generator = generator
|
||||
|
||||
def py__call__(self, params):
|
||||
def py__call__(self, evaluator, params):
|
||||
# TODO add TypeError if params are given.
|
||||
return self._generator.iter_content()
|
||||
|
||||
|
||||
@@ -66,6 +66,19 @@ class Instance(use_metaclass(CachedMetaClass, Executable)):
|
||||
# (No var_args) used.
|
||||
self.is_generated = False
|
||||
|
||||
@property
|
||||
def py__call__(self):
|
||||
def actual(evaluator, params):
|
||||
return evaluator.execute(method, params)
|
||||
|
||||
try:
|
||||
method = self.get_subscope_by_name('__call__')
|
||||
except KeyError:
|
||||
# Means the Instance is not callable.
|
||||
raise AttributeError
|
||||
|
||||
return actual
|
||||
|
||||
@memoize_default()
|
||||
def _get_method_execution(self, func):
|
||||
func = InstanceElement(self._evaluator, self, func, True)
|
||||
@@ -247,13 +260,13 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)):
|
||||
def is_callable(self):
|
||||
return self.var.is_callable()
|
||||
|
||||
def py__call__(self, params, evaluate_generator=False):
|
||||
def py__call__(self, evaluator, params, evaluate_generator=False):
|
||||
# TODO this should be working nicer.
|
||||
if isinstance(self.var, compiled.CompiledObject):
|
||||
return self.var.py__call__(self._evaluator, params)
|
||||
stmts = FunctionExecution(self._evaluator, self, params) \
|
||||
if isinstance(self.var, (compiled.CompiledObject, Instance)):
|
||||
return self.var.py__call__(evaluator, params)
|
||||
stmts = FunctionExecution(evaluator, self, params) \
|
||||
.get_return_types(evaluate_generator)
|
||||
return imports.follow_imports(self._evaluator, stmts)
|
||||
return imports.follow_imports(evaluator, stmts)
|
||||
|
||||
def __repr__(self):
|
||||
return "<%s of %s>" % (type(self).__name__, self.var)
|
||||
@@ -301,8 +314,8 @@ class Class(use_metaclass(CachedMetaClass, pr.IsScope)):
|
||||
supers += self._evaluator.find_types(compiled.builtin, 'object')
|
||||
return supers
|
||||
|
||||
def py__call__(self, params):
|
||||
return [Instance(self._evaluator, self, params)]
|
||||
def py__call__(self, evaluator, params):
|
||||
return [Instance(evaluator, self, params)]
|
||||
|
||||
@memoize_default(default=())
|
||||
def instance_names(self):
|
||||
@@ -424,10 +437,10 @@ class Function(use_metaclass(CachedMetaClass, pr.IsScope)):
|
||||
def is_callable(self):
|
||||
return True
|
||||
|
||||
def py__call__(self, params, evaluate_generator=False):
|
||||
stmts = FunctionExecution(self._evaluator, self, params) \
|
||||
def py__call__(self, evaluator, params, evaluate_generator=False):
|
||||
stmts = FunctionExecution(evaluator, self, params) \
|
||||
.get_return_types(evaluate_generator)
|
||||
return imports.follow_imports(self._evaluator, stmts)
|
||||
return imports.follow_imports(evaluator, stmts)
|
||||
|
||||
def __getattr__(self, name):
|
||||
return getattr(self.base_func, name)
|
||||
|
||||
Reference in New Issue
Block a user