1
0
forked from VimPlug/jedi

fix most issues related to the py__call__ stuff and generalize it.

This commit is contained in:
Dave Halter
2014-07-30 15:23:41 +02:00
parent 1e6a950aec
commit 373ff2c45a
3 changed files with 33 additions and 20 deletions

View File

@@ -325,24 +325,24 @@ class Evaluator(object):
pass pass
if isinstance(obj, iterable.GeneratorMethod): if isinstance(obj, iterable.GeneratorMethod):
return obj.py__call__(params) return obj.py__call__(self, params)
elif obj.isinstance(compiled.CompiledObject): elif obj.isinstance(compiled.CompiledObject):
return obj.py__call__(self, params) return obj.py__call__(self, params)
elif obj.isinstance(er.Class): elif obj.isinstance(er.Class):
# There maybe executions of executions. # There maybe executions of executions.
return obj.py__call__(params) return obj.py__call__(self, params)
else: else:
stmts = [] stmts = []
if obj.isinstance(er.Function): if obj.isinstance(er.Function):
return obj.py__call__(params, evaluate_generator) return obj.py__call__(self, params, evaluate_generator)
else: else:
if hasattr(obj, 'execute_subscope_by_name'):
try: try:
stmts = obj.execute_subscope_by_name('__call__', params) func = obj.py__call__
except KeyError: except AttributeError:
debug.warning("no __call__ func available %s", obj)
else:
debug.warning("no execution possible %s", obj) debug.warning("no execution possible %s", obj)
return []
else:
return func(self, params)
debug.dbg('execute result: %s in %s', stmts, obj) debug.dbg('execute result: %s in %s', stmts, obj)
return imports.follow_imports(self, stmts) return imports.follow_imports(self, stmts)

View File

@@ -94,7 +94,7 @@ class GeneratorMethod(object):
self._builtin_func = builtin_func self._builtin_func = builtin_func
self._generator = generator self._generator = generator
def py__call__(self, params): def py__call__(self, evaluator, params):
# TODO add TypeError if params are given. # TODO add TypeError if params are given.
return self._generator.iter_content() return self._generator.iter_content()

View File

@@ -66,6 +66,19 @@ class Instance(use_metaclass(CachedMetaClass, Executable)):
# (No var_args) used. # (No var_args) used.
self.is_generated = False 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() @memoize_default()
def _get_method_execution(self, func): def _get_method_execution(self, func):
func = InstanceElement(self._evaluator, self, func, True) func = InstanceElement(self._evaluator, self, func, True)
@@ -247,13 +260,13 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)):
def is_callable(self): def is_callable(self):
return self.var.is_callable() 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. # TODO this should be working nicer.
if isinstance(self.var, compiled.CompiledObject): if isinstance(self.var, (compiled.CompiledObject, Instance)):
return self.var.py__call__(self._evaluator, params) return self.var.py__call__(evaluator, params)
stmts = FunctionExecution(self._evaluator, self, params) \ stmts = FunctionExecution(evaluator, self, params) \
.get_return_types(evaluate_generator) .get_return_types(evaluate_generator)
return imports.follow_imports(self._evaluator, stmts) return imports.follow_imports(evaluator, stmts)
def __repr__(self): def __repr__(self):
return "<%s of %s>" % (type(self).__name__, self.var) 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') supers += self._evaluator.find_types(compiled.builtin, 'object')
return supers return supers
def py__call__(self, params): def py__call__(self, evaluator, params):
return [Instance(self._evaluator, self, params)] return [Instance(evaluator, self, params)]
@memoize_default(default=()) @memoize_default(default=())
def instance_names(self): def instance_names(self):
@@ -424,10 +437,10 @@ class Function(use_metaclass(CachedMetaClass, pr.IsScope)):
def is_callable(self): def is_callable(self):
return True return True
def py__call__(self, params, evaluate_generator=False): def py__call__(self, evaluator, params, evaluate_generator=False):
stmts = FunctionExecution(self._evaluator, self, params) \ stmts = FunctionExecution(evaluator, self, params) \
.get_return_types(evaluate_generator) .get_return_types(evaluate_generator)
return imports.follow_imports(self._evaluator, stmts) return imports.follow_imports(evaluator, stmts)
def __getattr__(self, name): def __getattr__(self, name):
return getattr(self.base_func, name) return getattr(self.base_func, name)