forked from VimPlug/jedi
execute_evaluated -> execute_with_values
This commit is contained in:
@@ -399,7 +399,7 @@ class BaseDefinition(object):
|
|||||||
return [Signature(self._evaluator, s) for s in self._name.infer().get_signatures()]
|
return [Signature(self._evaluator, s) for s in self._name.infer().get_signatures()]
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
return _contexts_to_definitions(self._name.infer().execute_evaluated())
|
return _contexts_to_definitions(self._name.infer().execute_with_values())
|
||||||
|
|
||||||
|
|
||||||
class Completion(BaseDefinition):
|
class Completion(BaseDefinition):
|
||||||
|
|||||||
@@ -38,13 +38,13 @@ class HelperContextMixin(object):
|
|||||||
def execute(self, arguments):
|
def execute(self, arguments):
|
||||||
return self.evaluator.execute(self, arguments=arguments)
|
return self.evaluator.execute(self, arguments=arguments)
|
||||||
|
|
||||||
def execute_evaluated(self, *value_list):
|
def execute_with_values(self, *value_list):
|
||||||
from jedi.evaluate.arguments import ValuesArguments
|
from jedi.evaluate.arguments import ValuesArguments
|
||||||
arguments = ValuesArguments([ContextSet([value]) for value in value_list])
|
arguments = ValuesArguments([ContextSet([value]) for value in value_list])
|
||||||
return self.evaluator.execute(self, arguments)
|
return self.evaluator.execute(self, arguments)
|
||||||
|
|
||||||
def execute_annotation(self):
|
def execute_annotation(self):
|
||||||
return self.execute_evaluated()
|
return self.execute_with_values()
|
||||||
|
|
||||||
def gather_annotation_classes(self):
|
def gather_annotation_classes(self):
|
||||||
return ContextSet([self])
|
return ContextSet([self])
|
||||||
@@ -75,7 +75,7 @@ class HelperContextMixin(object):
|
|||||||
await_context_set = self.py__getattribute__(u"__await__")
|
await_context_set = self.py__getattribute__(u"__await__")
|
||||||
if not await_context_set:
|
if not await_context_set:
|
||||||
debug.warning('Tried to run __await__ on context %s', self)
|
debug.warning('Tried to run __await__ on context %s', self)
|
||||||
return await_context_set.execute_evaluated()
|
return await_context_set.execute_with_values()
|
||||||
|
|
||||||
def eval_node(self, node):
|
def eval_node(self, node):
|
||||||
return self.evaluator.eval_element(self, node)
|
return self.evaluator.eval_element(self, node)
|
||||||
@@ -91,9 +91,9 @@ class HelperContextMixin(object):
|
|||||||
# TypeError: 'async for' requires an object with __aiter__ method, got int
|
# TypeError: 'async for' requires an object with __aiter__ method, got int
|
||||||
return iter([
|
return iter([
|
||||||
LazyKnownContexts(
|
LazyKnownContexts(
|
||||||
self.py__getattribute__('__aiter__').execute_evaluated()
|
self.py__getattribute__('__aiter__').execute_with_values()
|
||||||
.py__getattribute__('__anext__').execute_evaluated()
|
.py__getattribute__('__anext__').execute_with_values()
|
||||||
.py__getattribute__('__await__').execute_evaluated()
|
.py__getattribute__('__await__').execute_with_values()
|
||||||
.py__stop_iteration_returns()
|
.py__stop_iteration_returns()
|
||||||
) # noqa
|
) # noqa
|
||||||
])
|
])
|
||||||
@@ -397,8 +397,8 @@ class ContextSet(BaseContextSet):
|
|||||||
def execute(self, arguments):
|
def execute(self, arguments):
|
||||||
return ContextSet.from_sets(c.evaluator.execute(c, arguments) for c in self._set)
|
return ContextSet.from_sets(c.evaluator.execute(c, arguments) for c in self._set)
|
||||||
|
|
||||||
def execute_evaluated(self, *args, **kwargs):
|
def execute_with_values(self, *args, **kwargs):
|
||||||
return ContextSet.from_sets(c.execute_evaluated(*args, **kwargs) for c in self._set)
|
return ContextSet.from_sets(c.execute_with_values(*args, **kwargs) for c in self._set)
|
||||||
|
|
||||||
def py__getattribute__(self, *args, **kwargs):
|
def py__getattribute__(self, *args, **kwargs):
|
||||||
if kwargs.get('is_goto'):
|
if kwargs.get('is_goto'):
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class CompiledValue(LazyContextWrapper):
|
|||||||
|
|
||||||
def _get_wrapped_context(self):
|
def _get_wrapped_context(self):
|
||||||
instance, = builtin_from_name(
|
instance, = builtin_from_name(
|
||||||
self.evaluator, self._compiled_obj.name.string_name).execute_evaluated()
|
self.evaluator, self._compiled_obj.name.string_name).execute_with_values()
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@@ -50,7 +50,7 @@ def create_simple_object(evaluator, obj):
|
|||||||
|
|
||||||
|
|
||||||
def get_string_context_set(evaluator):
|
def get_string_context_set(evaluator):
|
||||||
return builtin_from_name(evaluator, u'str').execute_evaluated()
|
return builtin_from_name(evaluator, u'str').execute_with_values()
|
||||||
|
|
||||||
|
|
||||||
def load_module(evaluator, dotted_name, **kwargs):
|
def load_module(evaluator, dotted_name, **kwargs):
|
||||||
|
|||||||
@@ -328,7 +328,7 @@ class SignatureParamName(ParamNameInterface, AbstractNameDefinition):
|
|||||||
contexts = ContextSet([create_from_access_path(evaluator, p.default)])
|
contexts = ContextSet([create_from_access_path(evaluator, p.default)])
|
||||||
if p.has_annotation:
|
if p.has_annotation:
|
||||||
annotation = create_from_access_path(evaluator, p.annotation)
|
annotation = create_from_access_path(evaluator, p.annotation)
|
||||||
contexts |= annotation.execute_evaluated()
|
contexts |= annotation.execute_with_values()
|
||||||
return contexts
|
return contexts
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ def _create(evaluator, access_handle, parent_context, *args):
|
|||||||
if tree_node.type == 'classdef':
|
if tree_node.type == 'classdef':
|
||||||
if not access_handle.is_class():
|
if not access_handle.is_class():
|
||||||
# Is an instance, not a class.
|
# Is an instance, not a class.
|
||||||
tree_contexts = tree_contexts.execute_evaluated()
|
tree_contexts = tree_contexts.execute_with_values()
|
||||||
|
|
||||||
return ContextSet(
|
return ContextSet(
|
||||||
MixedObject(compiled_object, tree_context=tree_context)
|
MixedObject(compiled_object, tree_context=tree_context)
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class FunctionMixin(object):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
cls = self.py__class__()
|
cls = self.py__class__()
|
||||||
for instance in cls.execute_evaluated():
|
for instance in cls.execute_with_values():
|
||||||
for filter in instance.get_filters(search_global=False, origin_scope=origin_scope):
|
for filter in instance.get_filters(search_global=False, origin_scope=origin_scope):
|
||||||
yield filter
|
yield filter
|
||||||
|
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ class AbstractInstanceContext(Context):
|
|||||||
|
|
||||||
def execute_function_slots(self, names, *evaluated_args):
|
def execute_function_slots(self, names, *evaluated_args):
|
||||||
return ContextSet.from_sets(
|
return ContextSet.from_sets(
|
||||||
name.infer().execute_evaluated(*evaluated_args)
|
name.infer().execute_with_values(*evaluated_args)
|
||||||
for name in names
|
for name in names
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -793,7 +793,7 @@ class Slice(object):
|
|||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
if self._slice_object is None:
|
if self._slice_object is None:
|
||||||
context = compiled.builtin_from_name(self._context.evaluator, 'slice')
|
context = compiled.builtin_from_name(self._context.evaluator, 'slice')
|
||||||
self._slice_object, = context.execute_evaluated()
|
self._slice_object, = context.execute_with_values()
|
||||||
return getattr(self._slice_object, name)
|
return getattr(self._slice_object, name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@@ -284,7 +284,7 @@ def _check_isinstance_type(context, element, search_name):
|
|||||||
for cls_or_tup in lazy_context_cls.infer():
|
for cls_or_tup in lazy_context_cls.infer():
|
||||||
if isinstance(cls_or_tup, iterable.Sequence) and cls_or_tup.array_type == 'tuple':
|
if isinstance(cls_or_tup, iterable.Sequence) and cls_or_tup.array_type == 'tuple':
|
||||||
for lazy_context in cls_or_tup.py__iter__():
|
for lazy_context in cls_or_tup.py__iter__():
|
||||||
context_set |= lazy_context.infer().execute_evaluated()
|
context_set |= lazy_context.infer().execute_with_values()
|
||||||
else:
|
else:
|
||||||
context_set |= cls_or_tup.execute_evaluated()
|
context_set |= cls_or_tup.execute_with_values()
|
||||||
return context_set
|
return context_set
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ def _stub_to_python_context_set(stub_context, ignore_compiled=False):
|
|||||||
contexts = _infer_from_stub(stub_module, qualified_names, ignore_compiled)
|
contexts = _infer_from_stub(stub_module, qualified_names, ignore_compiled)
|
||||||
if was_instance:
|
if was_instance:
|
||||||
contexts = ContextSet.from_sets(
|
contexts = ContextSet.from_sets(
|
||||||
c.execute_evaluated()
|
c.execute_with_values()
|
||||||
for c in contexts
|
for c in contexts
|
||||||
if c.is_class()
|
if c.is_class()
|
||||||
)
|
)
|
||||||
@@ -188,7 +188,7 @@ def to_stub(context):
|
|||||||
|
|
||||||
if was_instance:
|
if was_instance:
|
||||||
stub_contexts = ContextSet.from_sets(
|
stub_contexts = ContextSet.from_sets(
|
||||||
c.execute_evaluated()
|
c.execute_with_values()
|
||||||
for c in stub_contexts
|
for c in stub_contexts
|
||||||
if c.is_class()
|
if c.is_class()
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ def eval_node(context, element):
|
|||||||
# Implies that it's a yield from.
|
# Implies that it's a yield from.
|
||||||
element = element.children[1].children[1]
|
element = element.children[1].children[1]
|
||||||
generators = context.eval_node(element) \
|
generators = context.eval_node(element) \
|
||||||
.py__getattribute__('__iter__').execute_evaluated()
|
.py__getattribute__('__iter__').execute_with_values()
|
||||||
return generators.py__stop_iteration_returns()
|
return generators.py__stop_iteration_returns()
|
||||||
|
|
||||||
# Generator.send() is not implemented.
|
# Generator.send() is not implemented.
|
||||||
@@ -391,7 +391,7 @@ def _literals_to_types(evaluator, result):
|
|||||||
# Literals are only valid as long as the operations are
|
# Literals are only valid as long as the operations are
|
||||||
# correct. Otherwise add a value-free instance.
|
# correct. Otherwise add a value-free instance.
|
||||||
cls = compiled.builtin_from_name(evaluator, typ.name.string_name)
|
cls = compiled.builtin_from_name(evaluator, typ.name.string_name)
|
||||||
new_result |= cls.execute_evaluated()
|
new_result |= cls.execute_with_values()
|
||||||
else:
|
else:
|
||||||
new_result |= ContextSet([typ])
|
new_result |= ContextSet([typ])
|
||||||
return new_result
|
return new_result
|
||||||
@@ -608,7 +608,7 @@ def tree_name_to_contexts(evaluator, context, tree_name):
|
|||||||
elif typ == 'with_stmt':
|
elif typ == 'with_stmt':
|
||||||
context_managers = context.eval_node(node.get_test_node_from_name(tree_name))
|
context_managers = context.eval_node(node.get_test_node_from_name(tree_name))
|
||||||
enter_methods = context_managers.py__getattribute__(u'__enter__')
|
enter_methods = context_managers.py__getattribute__(u'__enter__')
|
||||||
return enter_methods.execute_evaluated()
|
return enter_methods.execute_with_values()
|
||||||
elif typ in ('import_from', 'import_name'):
|
elif typ in ('import_from', 'import_name'):
|
||||||
types = imports.infer_import(context, tree_name)
|
types = imports.infer_import(context, tree_name)
|
||||||
elif typ in ('funcdef', 'classdef'):
|
elif typ in ('funcdef', 'classdef'):
|
||||||
@@ -618,7 +618,7 @@ def tree_name_to_contexts(evaluator, context, tree_name):
|
|||||||
# TODO check for types that are not classes and add it to
|
# TODO check for types that are not classes and add it to
|
||||||
# the static analysis report.
|
# the static analysis report.
|
||||||
exceptions = context.eval_node(tree_name.get_previous_sibling().get_previous_sibling())
|
exceptions = context.eval_node(tree_name.get_previous_sibling().get_previous_sibling())
|
||||||
types = exceptions.execute_evaluated()
|
types = exceptions.execute_with_values()
|
||||||
elif node.type == 'param':
|
elif node.type == 'param':
|
||||||
types = NO_CONTEXTS
|
types = NO_CONTEXTS
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -211,13 +211,13 @@ def builtins_next(iterators, defaults, evaluator):
|
|||||||
|
|
||||||
# TODO theoretically we have to check here if something is an iterator.
|
# TODO theoretically we have to check here if something is an iterator.
|
||||||
# That is probably done by checking if it's not a class.
|
# That is probably done by checking if it's not a class.
|
||||||
return defaults | iterators.py__getattribute__(name).execute_evaluated()
|
return defaults | iterators.py__getattribute__(name).execute_with_values()
|
||||||
|
|
||||||
|
|
||||||
@argument_clinic('iterator[, default], /')
|
@argument_clinic('iterator[, default], /')
|
||||||
def builtins_iter(iterators_or_callables, defaults):
|
def builtins_iter(iterators_or_callables, defaults):
|
||||||
# TODO implement this if it's a callable.
|
# TODO implement this if it's a callable.
|
||||||
return iterators_or_callables.py__getattribute__('__iter__').execute_evaluated()
|
return iterators_or_callables.py__getattribute__('__iter__').execute_with_values()
|
||||||
|
|
||||||
|
|
||||||
@argument_clinic('object, name[, default], /')
|
@argument_clinic('object, name[, default], /')
|
||||||
@@ -253,7 +253,7 @@ class SuperInstance(LazyContextWrapper):
|
|||||||
return self._instance.py__class__().py__bases__()
|
return self._instance.py__class__().py__bases__()
|
||||||
|
|
||||||
def _get_wrapped_context(self):
|
def _get_wrapped_context(self):
|
||||||
objs = self._get_bases()[0].infer().execute_evaluated()
|
objs = self._get_bases()[0].infer().execute_with_values()
|
||||||
if not objs:
|
if not objs:
|
||||||
# This is just a fallback and will only be used, if it's not
|
# This is just a fallback and will only be used, if it's not
|
||||||
# possible to find a class
|
# possible to find a class
|
||||||
@@ -262,7 +262,7 @@ class SuperInstance(LazyContextWrapper):
|
|||||||
|
|
||||||
def get_filters(self, search_global=False, until_position=None, origin_scope=None):
|
def get_filters(self, search_global=False, until_position=None, origin_scope=None):
|
||||||
for b in self._get_bases():
|
for b in self._get_bases():
|
||||||
for obj in b.infer().execute_evaluated():
|
for obj in b.infer().execute_with_values():
|
||||||
for f in obj.get_filters():
|
for f in obj.get_filters():
|
||||||
yield f
|
yield f
|
||||||
|
|
||||||
@@ -312,7 +312,7 @@ def builtins_reversed(sequences, obj, arguments):
|
|||||||
# necessary, because `reversed` is a function and autocompletion
|
# necessary, because `reversed` is a function and autocompletion
|
||||||
# would fail in certain cases like `reversed(x).__iter__` if we
|
# would fail in certain cases like `reversed(x).__iter__` if we
|
||||||
# just returned the result directly.
|
# just returned the result directly.
|
||||||
seq, = obj.evaluator.typing_module.py__getattribute__('Iterator').execute_evaluated()
|
seq, = obj.evaluator.typing_module.py__getattribute__('Iterator').execute_with_values()
|
||||||
return ContextSet([ReversedObject(seq, list(reversed(ordered)))])
|
return ContextSet([ReversedObject(seq, list(reversed(ordered)))])
|
||||||
|
|
||||||
|
|
||||||
@@ -813,7 +813,7 @@ class EnumInstance(LazyContextWrapper):
|
|||||||
return ContextName(self, self._name.tree_name)
|
return ContextName(self, self._name.tree_name)
|
||||||
|
|
||||||
def _get_wrapped_context(self):
|
def _get_wrapped_context(self):
|
||||||
obj, = self._cls.execute_evaluated()
|
obj, = self._cls.execute_with_values()
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def get_filters(self, search_global=False, position=None, origin_scope=None):
|
def get_filters(self, search_global=False, position=None, origin_scope=None):
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ from jedi.evaluate.gradual.conversion import _stub_to_python_context_set
|
|||||||
def test_simple(evaluator, environment):
|
def test_simple(evaluator, environment):
|
||||||
obj = compiled.create_simple_object(evaluator, u'_str_')
|
obj = compiled.create_simple_object(evaluator, u'_str_')
|
||||||
upper, = obj.py__getattribute__(u'upper')
|
upper, = obj.py__getattribute__(u'upper')
|
||||||
objs = list(upper.execute_evaluated())
|
objs = list(upper.execute_with_values())
|
||||||
assert len(objs) == 1
|
assert len(objs) == 1
|
||||||
if environment.version_info.major == 2:
|
if environment.version_info.major == 2:
|
||||||
expected = 'unicode'
|
expected = 'unicode'
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ def test_function_execution(Script):
|
|||||||
# Now just use the internals of the result (easiest way to get a fully
|
# Now just use the internals of the result (easiest way to get a fully
|
||||||
# usable function).
|
# usable function).
|
||||||
# Should return the same result both times.
|
# Should return the same result both times.
|
||||||
assert len(func.execute_evaluated()) == 1
|
assert len(func.execute_with_values()) == 1
|
||||||
assert len(func.execute_evaluated()) == 1
|
assert len(func.execute_with_values()) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_class_mro(Script):
|
def test_class_mro(Script):
|
||||||
|
|||||||
Reference in New Issue
Block a user