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