mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-30 08:44:21 +08:00
further progress in changing to py__call__
This commit is contained in:
@@ -318,17 +318,16 @@ class Evaluator(object):
|
||||
|
||||
debug.dbg('execute: %s %s', obj, params)
|
||||
try:
|
||||
# Some stdlib functions like super(), namedtuple(), etc. have been
|
||||
# hard-coded in Jedi to support them.
|
||||
return stdlib.execute(self, obj, params)
|
||||
except stdlib.NotInStdLib:
|
||||
pass
|
||||
|
||||
if isinstance(obj, iterable.GeneratorMethod):
|
||||
return obj.execute()
|
||||
return obj.py__call__(params)
|
||||
elif obj.isinstance(compiled.CompiledObject):
|
||||
if obj.is_executable_class():
|
||||
return [er.Instance(self, obj, params)]
|
||||
else:
|
||||
return list(obj.execute_function(self, params))
|
||||
return obj.py__call__(self, params)
|
||||
elif obj.isinstance(er.Class):
|
||||
# There maybe executions of executions.
|
||||
return obj.py__call__(params)
|
||||
|
||||
@@ -32,6 +32,13 @@ class CompiledObject(Base):
|
||||
self.obj = obj
|
||||
self.parent = parent
|
||||
|
||||
def py__call__(self, evaluator, params):
|
||||
if inspect.isclass(self.obj):
|
||||
from jedi.evaluate.representation import Instance
|
||||
return [Instance(evaluator, self, params)]
|
||||
else:
|
||||
return list(self._execute_function(evaluator, params))
|
||||
|
||||
@property
|
||||
def doc(self):
|
||||
return inspect.getdoc(self.obj) or ''
|
||||
@@ -73,9 +80,6 @@ class CompiledObject(Base):
|
||||
or inspect.ismethoddescriptor(cls):
|
||||
return 'function'
|
||||
|
||||
def is_executable_class(self):
|
||||
return inspect.isclass(self.obj)
|
||||
|
||||
@underscore_memoization
|
||||
def _cls(self):
|
||||
# Ensures that a CompiledObject is returned that is not an instance (like list)
|
||||
@@ -148,7 +152,7 @@ class CompiledObject(Base):
|
||||
# might not exist sometimes (raises AttributeError)
|
||||
return self._cls().obj.__name__
|
||||
|
||||
def execute_function(self, evaluator, params):
|
||||
def _execute_function(self, evaluator, params):
|
||||
if self.type() != 'function':
|
||||
return
|
||||
|
||||
|
||||
@@ -94,7 +94,8 @@ class GeneratorMethod(object):
|
||||
self._builtin_func = builtin_func
|
||||
self._generator = generator
|
||||
|
||||
def execute(self):
|
||||
def py__call__(self, params):
|
||||
# TODO add TypeError if params are given.
|
||||
return self._generator.iter_content()
|
||||
|
||||
def __getattr__(self, name):
|
||||
|
||||
@@ -248,6 +248,9 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)):
|
||||
return self.var.is_callable()
|
||||
|
||||
def py__call__(self, 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) \
|
||||
.get_return_types(evaluate_generator)
|
||||
return imports.follow_imports(self._evaluator, stmts)
|
||||
|
||||
Reference in New Issue
Block a user