forked from VimPlug/jedi
Move execute_evaluated to a helper function
This commit is contained in:
@@ -13,7 +13,7 @@ from jedi._compatibility import Python3Method, zip_longest, unicode
|
||||
from jedi.parser_utils import clean_scope_docstring, get_doc_with_call_signature
|
||||
from jedi.common import BaseContextSet, BaseContext
|
||||
from jedi.evaluate.helpers import EvaluatorIndexError, EvaluatorTypeError, \
|
||||
EvaluatorKeyError
|
||||
EvaluatorKeyError, execute_evaluated
|
||||
|
||||
|
||||
class Context(BaseContext):
|
||||
@@ -33,15 +33,6 @@ class Context(BaseContext):
|
||||
# overwritten.
|
||||
return self.__class__.__name__.lower()
|
||||
|
||||
def execute_evaluated(self, *value_list):
|
||||
"""
|
||||
Execute a function with already executed arguments.
|
||||
"""
|
||||
# TODO move this out of here to the evaluator.
|
||||
from jedi.evaluate.arguments import ValuesArguments
|
||||
arguments = ValuesArguments([ContextSet(value) for value in value_list])
|
||||
return self.evaluator.execute(self, arguments)
|
||||
|
||||
def iterate(self, contextualized_node=None, is_async=False):
|
||||
debug.dbg('iterate %s', self)
|
||||
try:
|
||||
@@ -240,6 +231,9 @@ class ContextSet(BaseContextSet):
|
||||
def execute(self, arguments):
|
||||
return ContextSet.from_sets(c.evaluator.execute(c, arguments) for c in self._set)
|
||||
|
||||
def execute_evaluated(self, *args, **kwargs):
|
||||
return ContextSet.from_sets(execute_evaluated(c, *args, **kwargs) for c in self._set)
|
||||
|
||||
|
||||
NO_CONTEXTS = ContextSet()
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ from jedi._compatibility import unicode
|
||||
from jedi.evaluate.compiled.context import CompiledObject, CompiledName, \
|
||||
CompiledObjectFilter, CompiledContextName, create_from_access_path, \
|
||||
create_from_name
|
||||
from jedi.evaluate.helpers import execute_evaluated
|
||||
|
||||
|
||||
def builtin_from_name(evaluator, string):
|
||||
@@ -29,7 +30,7 @@ def get_special_object(evaluator, identifier):
|
||||
|
||||
|
||||
def get_string_context_set(evaluator):
|
||||
return builtin_from_name(evaluator, u'str').execute_evaluated()
|
||||
return execute_evaluated(builtin_from_name(evaluator, u'str'))
|
||||
|
||||
|
||||
def load_module(evaluator, **kwargs):
|
||||
|
||||
@@ -13,7 +13,7 @@ from jedi.evaluate.base_context import Context, ContextSet
|
||||
from jedi.evaluate.lazy_context import LazyKnownContext
|
||||
from jedi.evaluate.compiled.access import _sentinel
|
||||
from jedi.evaluate.cache import evaluator_function_cache
|
||||
from jedi.evaluate.helpers import reraise_as_evaluator
|
||||
from jedi.evaluate.helpers import reraise_as_evaluator, execute_evaluated
|
||||
from . import fake
|
||||
|
||||
|
||||
@@ -268,7 +268,7 @@ class SignatureParamName(AbstractNameDefinition):
|
||||
contexts = ContextSet(create_from_access_path(evaluator, p.default))
|
||||
if p.has_annotation:
|
||||
annotation = create_from_access_path(evaluator, p.annotation)
|
||||
contexts |= annotation.execute_evaluated()
|
||||
contexts |= execute_evaluated(annotation)
|
||||
return contexts
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ from jedi.evaluate import imports
|
||||
from jedi.evaluate.base_context import Context, ContextSet
|
||||
from jedi.evaluate.context import ModuleContext
|
||||
from jedi.evaluate.cache import evaluator_function_cache
|
||||
from jedi.evaluate.helpers import execute_evaluated
|
||||
from jedi.evaluate.compiled.getattr_static import getattr_static
|
||||
from jedi.evaluate.compiled.access import compiled_objects_cache
|
||||
from jedi.evaluate.compiled.context import create_cached_compiled_object
|
||||
@@ -220,7 +221,7 @@ def _create(evaluator, access_handle, parent_context, *args):
|
||||
if tree_node.type == 'classdef':
|
||||
if not access_handle.is_class():
|
||||
# Is an instance, not a class.
|
||||
tree_context, = tree_context.execute_evaluated()
|
||||
tree_context, = execute_evaluated(tree_context)
|
||||
|
||||
return MixedObject(
|
||||
evaluator,
|
||||
|
||||
@@ -35,6 +35,7 @@ from jedi.evaluate.helpers import get_int_or_none, is_string, \
|
||||
from jedi.evaluate.utils import safe_property
|
||||
from jedi.evaluate.utils import to_list
|
||||
from jedi.evaluate.cache import evaluator_method_cache
|
||||
from jedi.evaluate.helpers import execute_evaluated
|
||||
from jedi.evaluate.filters import ParserTreeFilter, BuiltinOverwrite, \
|
||||
publish_method
|
||||
from jedi.evaluate.base_context import ContextSet, NO_CONTEXTS, Context, \
|
||||
@@ -188,7 +189,7 @@ class Sequence(BuiltinOverwrite, IterableMixin):
|
||||
@memoize_method
|
||||
def get_object(self):
|
||||
compiled_obj = compiled.builtin_from_name(self.evaluator, self.array_type)
|
||||
only_obj, = compiled_obj.execute_evaluated(self)
|
||||
only_obj, = execute_evaluated(compiled_obj, self)
|
||||
return only_obj
|
||||
|
||||
def py__bool__(self):
|
||||
|
||||
@@ -23,6 +23,7 @@ from parso import parse, ParserSyntaxError
|
||||
from jedi._compatibility import u
|
||||
from jedi.evaluate.utils import indent_block
|
||||
from jedi.evaluate.cache import evaluator_method_cache
|
||||
from jedi.evaluate.helpers import execute_evaluated
|
||||
from jedi.evaluate.base_context import iterator_to_context_set, ContextSet, \
|
||||
NO_CONTEXTS
|
||||
from jedi.evaluate.lazy_context import LazyKnownContexts
|
||||
@@ -261,7 +262,7 @@ def _execute_array_values(evaluator, array):
|
||||
values.append(LazyKnownContexts(objects))
|
||||
return {FakeSequence(evaluator, array.array_type, values)}
|
||||
else:
|
||||
return array.execute_evaluated()
|
||||
return execute_evaluated(array)
|
||||
|
||||
|
||||
@evaluator_method_cache()
|
||||
|
||||
@@ -271,8 +271,7 @@ def _check_isinstance_type(context, element, search_name):
|
||||
for cls_or_tup in lazy_context_cls.infer():
|
||||
if isinstance(cls_or_tup, iterable.Sequence) and cls_or_tup.array_type == 'tuple':
|
||||
for lazy_context in cls_or_tup.py__iter__():
|
||||
for context in lazy_context.infer():
|
||||
context_set |= context.execute_evaluated()
|
||||
context_set |= lazy_context.infer().execute_evaluated(context)
|
||||
else:
|
||||
context_set |= cls_or_tup.execute_evaluated()
|
||||
context_set |= helpers.execute_evaluated(cls_or_tup)
|
||||
return context_set
|
||||
|
||||
@@ -237,3 +237,14 @@ def reraise_as_evaluator(*exception_classes):
|
||||
except exception_classes as e:
|
||||
new_exc_cls = globals()['Evaluator' + e.__class__.__name__]
|
||||
raise new_exc_cls(e)
|
||||
|
||||
|
||||
def execute_evaluated(context, *value_list):
|
||||
"""
|
||||
Execute a function with already executed arguments.
|
||||
"""
|
||||
# TODO move this out of here to the evaluator.
|
||||
from jedi.evaluate.arguments import ValuesArguments
|
||||
from jedi.evaluate.base_context import ContextSet
|
||||
arguments = ValuesArguments([ContextSet(value) for value in value_list])
|
||||
return context.evaluator.execute(context, arguments)
|
||||
|
||||
@@ -31,7 +31,7 @@ from jedi.evaluate import compiled
|
||||
from jedi.evaluate.base_context import NO_CONTEXTS, ContextSet
|
||||
from jedi.evaluate.lazy_context import LazyTreeContext
|
||||
from jedi.evaluate.context import ModuleContext
|
||||
from jedi.evaluate.helpers import is_string
|
||||
from jedi.evaluate.helpers import is_string, execute_evaluated
|
||||
from jedi import debug
|
||||
from jedi import parser_utils
|
||||
|
||||
@@ -296,7 +296,7 @@ def py__getitem__(context, typ, node):
|
||||
[LazyTreeContext(context, n) for n in nodes]
|
||||
)
|
||||
|
||||
result = factory.execute_evaluated(compiled_classname, args)
|
||||
result = execute_evaluated(factory, compiled_classname, args)
|
||||
return result
|
||||
|
||||
|
||||
|
||||
@@ -393,7 +393,7 @@ def _literals_to_types(evaluator, result):
|
||||
# Literals are only valid as long as the operations are
|
||||
# correct. Otherwise add a value-free instance.
|
||||
cls = compiled.builtin_from_name(evaluator, typ.name.string_name)
|
||||
new_result |= cls.execute_evaluated()
|
||||
new_result |= helpers.execute_evaluated(cls)
|
||||
else:
|
||||
new_result |= ContextSet(typ)
|
||||
return new_result
|
||||
|
||||
Reference in New Issue
Block a user