forked from VimPlug/jedi
py__call__ is now always available
This commit is contained in:
@@ -90,16 +90,10 @@ from jedi.evaluate.gradual.conversion import try_stub_to_actual_names, \
|
|||||||
|
|
||||||
def _execute(context, arguments):
|
def _execute(context, arguments):
|
||||||
debug.dbg('execute: %s %s', context, arguments)
|
debug.dbg('execute: %s %s', context, arguments)
|
||||||
try:
|
with debug.increase_indent_cm():
|
||||||
func = context.py__call__
|
context_set = context.py__call__(arguments=arguments)
|
||||||
except AttributeError:
|
debug.dbg('execute result: %s in %s', context_set, context)
|
||||||
debug.warning("no execution possible %s", context)
|
return context_set
|
||||||
return NO_CONTEXTS
|
|
||||||
else:
|
|
||||||
with debug.increase_indent_cm():
|
|
||||||
context_set = func(arguments=arguments)
|
|
||||||
debug.dbg('execute result: %s in %s', context_set, context)
|
|
||||||
return context_set
|
|
||||||
|
|
||||||
|
|
||||||
class Evaluator(object):
|
class Evaluator(object):
|
||||||
|
|||||||
@@ -185,6 +185,10 @@ class Context(HelperContextMixin, BaseContext):
|
|||||||
return clean_scope_docstring(self.tree_node)
|
return clean_scope_docstring(self.tree_node)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def py__call__(self, arguments):
|
||||||
|
debug.warning("no execution possible %s", self)
|
||||||
|
return NO_CONTEXTS
|
||||||
|
|
||||||
def py__stop_iteration_returns(self):
|
def py__stop_iteration_returns(self):
|
||||||
debug.warning("Not possible to return the stop iterations of %s", self)
|
debug.warning("Not possible to return the stop iterations of %s", self)
|
||||||
return NO_CONTEXTS
|
return NO_CONTEXTS
|
||||||
|
|||||||
@@ -45,15 +45,19 @@ class CompiledObject(Context):
|
|||||||
super(CompiledObject, self).__init__(evaluator, parent_context)
|
super(CompiledObject, self).__init__(evaluator, parent_context)
|
||||||
self.access_handle = access_handle
|
self.access_handle = access_handle
|
||||||
|
|
||||||
@CheckAttribute()
|
|
||||||
def py__call__(self, arguments):
|
def py__call__(self, arguments):
|
||||||
if self.access_handle.is_class():
|
try:
|
||||||
from jedi.evaluate.context import CompiledInstance
|
self.access_handle.getattr_paths(u'__call__')
|
||||||
return ContextSet([
|
except AttributeError:
|
||||||
CompiledInstance(self.evaluator, self.parent_context, self, arguments)
|
return super(CompiledObject, self).py__call__(arguments)
|
||||||
])
|
|
||||||
else:
|
else:
|
||||||
return ContextSet(self._execute_function(arguments))
|
if self.access_handle.is_class():
|
||||||
|
from jedi.evaluate.context import CompiledInstance
|
||||||
|
return ContextSet([
|
||||||
|
CompiledInstance(self.evaluator, self.parent_context, self, arguments)
|
||||||
|
])
|
||||||
|
else:
|
||||||
|
return ContextSet(self._execute_function(arguments))
|
||||||
|
|
||||||
@CheckAttribute()
|
@CheckAttribute()
|
||||||
def py__class__(self):
|
def py__class__(self):
|
||||||
|
|||||||
@@ -76,17 +76,13 @@ class AbstractInstanceContext(Context):
|
|||||||
def get_annotated_class_object(self):
|
def get_annotated_class_object(self):
|
||||||
return self.class_context # This is the default.
|
return self.class_context # This is the default.
|
||||||
|
|
||||||
@property
|
def py__call__(self, arguments):
|
||||||
def py__call__(self):
|
|
||||||
names = self.get_function_slot_names(u'__call__')
|
names = self.get_function_slot_names(u'__call__')
|
||||||
if not names:
|
if not names:
|
||||||
# Means the Instance is not callable.
|
# Means the Instance is not callable.
|
||||||
raise AttributeError
|
return super(AbstractInstanceContext, self).py__call__(arguments)
|
||||||
|
|
||||||
def execute(arguments):
|
return ContextSet.from_sets(name.infer().execute(arguments) for name in names)
|
||||||
return ContextSet.from_sets(name.infer().execute(arguments) for name in names)
|
|
||||||
|
|
||||||
return execute
|
|
||||||
|
|
||||||
def py__class__(self):
|
def py__class__(self):
|
||||||
return self.class_context
|
return self.class_context
|
||||||
|
|||||||
@@ -385,11 +385,15 @@ def test_sys_path_docstring(): # Was an issue in #1298
|
|||||||
('z[0].append', ['append']),
|
('z[0].append', ['append']),
|
||||||
('z[1].uppe', ['upper']),
|
('z[1].uppe', ['upper']),
|
||||||
('z[1].append', []),
|
('z[1].append', []),
|
||||||
|
|
||||||
|
('collections.deque().app', ['append', 'appendleft']),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_simple_completions(code, completions):
|
def test_simple_completions(code, completions):
|
||||||
x = [str]
|
x = [str]
|
||||||
y = {1}
|
y = {1}
|
||||||
z = {1: str, 2: list}
|
z = {1: str, 2: list}
|
||||||
|
import collections
|
||||||
|
|
||||||
defs = jedi.Interpreter(code, [locals()]).completions()
|
defs = jedi.Interpreter(code, [locals()]).completions()
|
||||||
assert [d.name for d in defs] == completions
|
assert [d.name for d in defs] == completions
|
||||||
|
|||||||
Reference in New Issue
Block a user