mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
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):
|
||||
debug.dbg('execute: %s %s', context, arguments)
|
||||
try:
|
||||
func = context.py__call__
|
||||
except AttributeError:
|
||||
debug.warning("no execution possible %s", context)
|
||||
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
|
||||
with debug.increase_indent_cm():
|
||||
context_set = context.py__call__(arguments=arguments)
|
||||
debug.dbg('execute result: %s in %s', context_set, context)
|
||||
return context_set
|
||||
|
||||
|
||||
class Evaluator(object):
|
||||
|
||||
@@ -185,6 +185,10 @@ class Context(HelperContextMixin, BaseContext):
|
||||
return clean_scope_docstring(self.tree_node)
|
||||
return None
|
||||
|
||||
def py__call__(self, arguments):
|
||||
debug.warning("no execution possible %s", self)
|
||||
return NO_CONTEXTS
|
||||
|
||||
def py__stop_iteration_returns(self):
|
||||
debug.warning("Not possible to return the stop iterations of %s", self)
|
||||
return NO_CONTEXTS
|
||||
|
||||
@@ -45,15 +45,19 @@ class CompiledObject(Context):
|
||||
super(CompiledObject, self).__init__(evaluator, parent_context)
|
||||
self.access_handle = access_handle
|
||||
|
||||
@CheckAttribute()
|
||||
def py__call__(self, arguments):
|
||||
if self.access_handle.is_class():
|
||||
from jedi.evaluate.context import CompiledInstance
|
||||
return ContextSet([
|
||||
CompiledInstance(self.evaluator, self.parent_context, self, arguments)
|
||||
])
|
||||
try:
|
||||
self.access_handle.getattr_paths(u'__call__')
|
||||
except AttributeError:
|
||||
return super(CompiledObject, self).py__call__(arguments)
|
||||
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()
|
||||
def py__class__(self):
|
||||
|
||||
@@ -76,17 +76,13 @@ class AbstractInstanceContext(Context):
|
||||
def get_annotated_class_object(self):
|
||||
return self.class_context # This is the default.
|
||||
|
||||
@property
|
||||
def py__call__(self):
|
||||
def py__call__(self, arguments):
|
||||
names = self.get_function_slot_names(u'__call__')
|
||||
if not names:
|
||||
# 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 execute
|
||||
return ContextSet.from_sets(name.infer().execute(arguments) for name in names)
|
||||
|
||||
def py__class__(self):
|
||||
return self.class_context
|
||||
|
||||
@@ -385,11 +385,15 @@ def test_sys_path_docstring(): # Was an issue in #1298
|
||||
('z[0].append', ['append']),
|
||||
('z[1].uppe', ['upper']),
|
||||
('z[1].append', []),
|
||||
|
||||
('collections.deque().app', ['append', 'appendleft']),
|
||||
]
|
||||
)
|
||||
def test_simple_completions(code, completions):
|
||||
x = [str]
|
||||
y = {1}
|
||||
z = {1: str, 2: list}
|
||||
import collections
|
||||
|
||||
defs = jedi.Interpreter(code, [locals()]).completions()
|
||||
assert [d.name for d in defs] == completions
|
||||
|
||||
Reference in New Issue
Block a user