mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Move execute_evaluated to HelperContextMixin
This commit is contained in:
@@ -14,7 +14,7 @@ from jedi import debug
|
||||
from jedi._compatibility import zip_longest, unicode
|
||||
from jedi.parser_utils import clean_scope_docstring
|
||||
from jedi.common import BaseContextSet, BaseContext
|
||||
from jedi.evaluate.helpers import SimpleGetItemNotFound, execute_evaluated
|
||||
from jedi.evaluate.helpers import SimpleGetItemNotFound
|
||||
from jedi.evaluate.utils import safe_property
|
||||
from jedi.evaluate.cache import evaluator_as_method_param_cache
|
||||
from jedi.cache import memoize_method
|
||||
@@ -39,7 +39,9 @@ class HelperContextMixin(object):
|
||||
return self.evaluator.execute(self, arguments=arguments)
|
||||
|
||||
def execute_evaluated(self, *value_list):
|
||||
return execute_evaluated(self, *value_list)
|
||||
from jedi.evaluate.arguments import ValuesArguments
|
||||
arguments = ValuesArguments([ContextSet([value]) for value in value_list])
|
||||
return self.evaluator.execute(self, arguments)
|
||||
|
||||
def execute_annotation(self):
|
||||
return self.execute_evaluated()
|
||||
@@ -396,7 +398,7 @@ class ContextSet(BaseContextSet):
|
||||
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)
|
||||
return ContextSet.from_sets(c.execute_evaluated(*args, **kwargs) for c in self._set)
|
||||
|
||||
def py__getattribute__(self, *args, **kwargs):
|
||||
if kwargs.get('is_goto'):
|
||||
|
||||
@@ -2,7 +2,6 @@ from jedi._compatibility import unicode
|
||||
from jedi.evaluate.compiled.context import CompiledObject, CompiledName, \
|
||||
CompiledObjectFilter, CompiledContextName, create_from_access_path
|
||||
from jedi.evaluate.base_context import ContextWrapper
|
||||
from jedi.evaluate.helpers import execute_evaluated
|
||||
|
||||
|
||||
def builtin_from_name(evaluator, string):
|
||||
@@ -47,7 +46,7 @@ def create_simple_object(evaluator, obj):
|
||||
|
||||
|
||||
def get_string_context_set(evaluator):
|
||||
return execute_evaluated(builtin_from_name(evaluator, u'str'))
|
||||
return builtin_from_name(evaluator, u'str').execute_evaluated()
|
||||
|
||||
|
||||
def load_module(evaluator, dotted_name, **kwargs):
|
||||
|
||||
@@ -15,7 +15,7 @@ from jedi.evaluate.base_context import Context, ContextSet, NO_CONTEXTS
|
||||
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_getitem_errors, execute_evaluated
|
||||
from jedi.evaluate.helpers import reraise_getitem_errors
|
||||
from jedi.evaluate.signature import BuiltinSignature
|
||||
|
||||
|
||||
@@ -318,7 +318,7 @@ class SignatureParamName(AbstractNameDefinition, ParamNameInterface):
|
||||
contexts = ContextSet([create_from_access_path(evaluator, p.default)])
|
||||
if p.has_annotation:
|
||||
annotation = create_from_access_path(evaluator, p.annotation)
|
||||
contexts |= execute_evaluated(annotation)
|
||||
contexts |= annotation.execute_evaluated()
|
||||
return contexts
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ from jedi.evaluate.helpers import get_int_or_none, is_string, \
|
||||
SimpleGetItemNotFound
|
||||
from jedi.evaluate.utils import safe_property, to_list
|
||||
from jedi.evaluate.cache import evaluator_method_cache
|
||||
from jedi.evaluate.helpers import execute_evaluated
|
||||
from jedi.evaluate.filters import ParserTreeFilter, LazyAttributeOverwrite, \
|
||||
publish_method
|
||||
from jedi.evaluate.base_context import ContextSet, NO_CONTEXTS, \
|
||||
@@ -772,7 +771,7 @@ class Slice(object):
|
||||
def __getattr__(self, name):
|
||||
if self._slice_object is None:
|
||||
context = compiled.builtin_from_name(self._context.evaluator, 'slice')
|
||||
self._slice_object, = execute_evaluated(context)
|
||||
self._slice_object, = context.execute_evaluated()
|
||||
return getattr(self._slice_object, name)
|
||||
|
||||
@property
|
||||
|
||||
@@ -236,17 +236,6 @@ def reraise_getitem_errors(*exception_classes):
|
||||
raise SimpleGetItemNotFound(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)
|
||||
|
||||
|
||||
def parse_dotted_names(nodes, is_import_from, until_node=None):
|
||||
level = 0
|
||||
names = []
|
||||
|
||||
@@ -389,7 +389,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 |= helpers.execute_evaluated(cls)
|
||||
new_result |= cls.execute_evaluated()
|
||||
else:
|
||||
new_result |= ContextSet([typ])
|
||||
return new_result
|
||||
|
||||
@@ -8,14 +8,13 @@ import pytest
|
||||
|
||||
from jedi.evaluate import compiled
|
||||
from jedi.evaluate.compiled.access import DirectObjectAccess
|
||||
from jedi.evaluate.helpers import execute_evaluated
|
||||
from jedi.evaluate.gradual.conversion import _stub_to_python_context_set
|
||||
|
||||
|
||||
def test_simple(evaluator, environment):
|
||||
obj = compiled.create_simple_object(evaluator, u'_str_')
|
||||
upper, = obj.py__getattribute__(u'upper')
|
||||
objs = list(execute_evaluated(upper))
|
||||
objs = list(upper.execute_evaluated())
|
||||
assert len(objs) == 1
|
||||
if environment.version_info.major == 2:
|
||||
expected = 'unicode'
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
from textwrap import dedent
|
||||
|
||||
from jedi.evaluate.helpers import execute_evaluated
|
||||
|
||||
|
||||
def get_definition_and_evaluator(Script, source):
|
||||
first, = Script(dedent(source)).goto_definitions()
|
||||
@@ -22,8 +20,8 @@ def test_function_execution(Script):
|
||||
# Now just use the internals of the result (easiest way to get a fully
|
||||
# usable function).
|
||||
# Should return the same result both times.
|
||||
assert len(execute_evaluated(func)) == 1
|
||||
assert len(execute_evaluated(func)) == 1
|
||||
assert len(func.execute_evaluated()) == 1
|
||||
assert len(func.execute_evaluated()) == 1
|
||||
|
||||
|
||||
def test_class_mro(Script):
|
||||
|
||||
Reference in New Issue
Block a user