mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-21 21:11:13 +08:00
Move lazy contexts to a separate module not in contexts
This commit is contained in:
@@ -14,6 +14,7 @@ from jedi.cache import underscore_memoization, memoize_method
|
||||
from jedi.evaluate.filters import AbstractFilter, AbstractNameDefinition, \
|
||||
ContextNameMixin
|
||||
from jedi.evaluate.base_context import Context, ContextSet
|
||||
from jedi.evaluate.lazy_context import LazyKnownContext
|
||||
from jedi.evaluate.compiled.getattr_static import getattr_static
|
||||
from . import fake
|
||||
|
||||
@@ -231,7 +232,6 @@ class CompiledObject(Context):
|
||||
# Get rid of side effects, we won't call custom `__getitem__`s.
|
||||
return
|
||||
|
||||
from jedi.evaluate.context import LazyKnownContext
|
||||
for i, part in enumerate(self.obj):
|
||||
if i > 20:
|
||||
# Should not go crazy with large iterators
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from jedi.evaluate.context.lazy import AbstractLazyContext, LazyKnownContext, \
|
||||
LazyKnownContexts, LazyTreeContext, LazyUnknownContext, get_merged_lazy_context
|
||||
from jedi.evaluate.context.module import ModuleContext
|
||||
from jedi.evaluate.context.klass import ClassContext
|
||||
#from jedi.evaluate.context.function import FunctionContext
|
||||
|
||||
@@ -14,7 +14,8 @@ from jedi.evaluate.filters import ParserTreeFilter, FunctionExecutionFilter, \
|
||||
ContextName, AbstractNameDefinition, ParamName
|
||||
from jedi.evaluate.base_context import ContextualizedNode, NO_CONTEXTS, \
|
||||
ContextSet, TreeContext
|
||||
from jedi.evaluate.context import LazyKnownContexts, LazyKnownContext, LazyTreeContext
|
||||
from jedi.evaluate.lazy_context import LazyKnownContexts, LazyKnownContext, \
|
||||
LazyTreeContext
|
||||
from jedi.evaluate.context import iterable
|
||||
from jedi import parser_utils
|
||||
from jedi.evaluate.parser_cache import get_yield_exprs
|
||||
|
||||
@@ -6,7 +6,7 @@ from jedi.evaluate import compiled
|
||||
from jedi.evaluate import filters
|
||||
from jedi.evaluate.base_context import Context, NO_CONTEXTS, ContextSet, \
|
||||
iterator_to_context_set
|
||||
from jedi.evaluate.context import LazyKnownContext, LazyKnownContexts
|
||||
from jedi.evaluate.lazy_context import LazyKnownContext, LazyKnownContexts
|
||||
from jedi.evaluate.cache import evaluator_method_cache
|
||||
from jedi.evaluate.param import AbstractArguments, AnonymousArguments
|
||||
from jedi.cache import memoize_method
|
||||
|
||||
@@ -24,8 +24,9 @@ from jedi import debug
|
||||
from jedi import settings
|
||||
from jedi.evaluate import compiled
|
||||
from jedi.evaluate import analysis
|
||||
from jedi.evaluate import context
|
||||
from jedi.evaluate import recursion
|
||||
from jedi.evaluate.lazy_context import LazyKnownContext, LazyKnownContexts, \
|
||||
LazyTreeContext
|
||||
from jedi.evaluate.helpers import is_string, predefine_names, evaluate_call_of_leaf
|
||||
from jedi.evaluate.utils import safe_property
|
||||
from jedi.evaluate.utils import to_list
|
||||
@@ -187,7 +188,7 @@ class Comprehension(AbstractIterable):
|
||||
|
||||
def py__iter__(self):
|
||||
for set_ in self._iterate():
|
||||
yield context.LazyKnownContexts(set_)
|
||||
yield LazyKnownContexts(set_)
|
||||
|
||||
def __repr__(self):
|
||||
return "<%s of %s>" % (type(self).__name__, self._atom)
|
||||
@@ -243,7 +244,7 @@ class DictComprehension(ArrayMixin, Comprehension):
|
||||
|
||||
def py__iter__(self):
|
||||
for keys, values in self._iterate():
|
||||
yield context.LazyKnownContexts(keys)
|
||||
yield LazyKnownContexts(keys)
|
||||
|
||||
def py__getitem__(self, index):
|
||||
for keys, values in self._iterate():
|
||||
@@ -258,7 +259,7 @@ class DictComprehension(ArrayMixin, Comprehension):
|
||||
|
||||
@register_builtin_method('values')
|
||||
def _imitate_values(self):
|
||||
lazy_context = context.LazyKnownContexts(self.dict_values())
|
||||
lazy_context = LazyKnownContexts(self.dict_values())
|
||||
return ContextSet(FakeSequence(self.evaluator, 'list', [lazy_context]))
|
||||
|
||||
@register_builtin_method('items')
|
||||
@@ -266,7 +267,7 @@ class DictComprehension(ArrayMixin, Comprehension):
|
||||
items = ContextSet.from_iterable(
|
||||
FakeSequence(
|
||||
self.evaluator, 'tuple'
|
||||
(context.LazyKnownContexts(keys), context.LazyKnownContexts(values))
|
||||
(LazyKnownContexts(keys), LazyKnownContexts(values))
|
||||
) for keys, values in self._iterate()
|
||||
)
|
||||
|
||||
@@ -322,10 +323,10 @@ class SequenceLiteralContext(ArrayMixin, AbstractIterable):
|
||||
# We don't know which dict index comes first, therefore always
|
||||
# yield all the types.
|
||||
for _ in types:
|
||||
yield context.LazyKnownContexts(types)
|
||||
yield LazyKnownContexts(types)
|
||||
else:
|
||||
for node in self._items():
|
||||
yield context.LazyTreeContext(self._defining_context, node)
|
||||
yield LazyTreeContext(self._defining_context, node)
|
||||
|
||||
for addition in check_array_additions(self._defining_context, self):
|
||||
yield addition
|
||||
@@ -372,7 +373,7 @@ class SequenceLiteralContext(ArrayMixin, AbstractIterable):
|
||||
for key_node, value in self._items():
|
||||
for key in self._defining_context.eval_node(key_node):
|
||||
if is_string(key):
|
||||
yield key.obj, context.LazyTreeContext(self._defining_context, value)
|
||||
yield key.obj, LazyTreeContext(self._defining_context, value)
|
||||
|
||||
def __repr__(self):
|
||||
return "<%s of %s>" % (self.__class__.__name__, self.atom)
|
||||
@@ -389,16 +390,16 @@ class DictLiteralContext(SequenceLiteralContext):
|
||||
|
||||
@register_builtin_method('values')
|
||||
def _imitate_values(self):
|
||||
lazy_context = context.LazyKnownContexts(self.dict_values())
|
||||
lazy_context = LazyKnownContexts(self.dict_values())
|
||||
return ContextSet(FakeSequence(self.evaluator, 'list', [lazy_context]))
|
||||
|
||||
@register_builtin_method('items')
|
||||
def _imitate_items(self):
|
||||
lazy_contexts = [
|
||||
context.LazyKnownContext(FakeSequence(
|
||||
LazyKnownContext(FakeSequence(
|
||||
self.evaluator, 'tuple',
|
||||
(context.LazyTreeContext(self._defining_context, key_node),
|
||||
context.LazyTreeContext(self._defining_context, value_node))
|
||||
(LazyTreeContext(self._defining_context, key_node),
|
||||
LazyTreeContext(self._defining_context, value_node))
|
||||
)) for key_node, value_node in self._items()
|
||||
]
|
||||
|
||||
@@ -441,7 +442,7 @@ class FakeDict(_FakeArray):
|
||||
|
||||
def py__iter__(self):
|
||||
for key in self._dct:
|
||||
yield context.LazyKnownContext(compiled.create(self.evaluator, key))
|
||||
yield LazyKnownContext(compiled.create(self.evaluator, key))
|
||||
|
||||
def py__getitem__(self, index):
|
||||
return self._dct[index].infer()
|
||||
|
||||
@@ -40,6 +40,7 @@ py__doc__(include_call_signature: Returns the docstring for a context.
|
||||
from jedi._compatibility import use_metaclass
|
||||
from jedi.evaluate.cache import evaluator_method_cache, CachedMetaClass
|
||||
from jedi.evaluate import compiled
|
||||
from jedi.evaluate.lazy_context import LazyKnownContext
|
||||
from jedi.evaluate.filters import ParserTreeFilter, TreeNameDefinition, \
|
||||
ContextName, AnonymousInstanceParamName
|
||||
from jedi.evaluate.base_context import ContextSet, iterator_to_context_set, \
|
||||
@@ -138,7 +139,6 @@ class ClassContext(use_metaclass(CachedMetaClass, TreeContext)):
|
||||
args = param.TreeArguments(self.evaluator, self, arglist)
|
||||
return [value for key, value in args.unpack() if key is None]
|
||||
else:
|
||||
from jedi.evaluate.context import LazyKnownContext
|
||||
return [LazyKnownContext(compiled.create(self.evaluator, object))]
|
||||
|
||||
def py__call__(self, params):
|
||||
|
||||
@@ -25,7 +25,7 @@ from jedi.evaluate.utils import indent_block
|
||||
from jedi.evaluate.cache import evaluator_method_cache
|
||||
from jedi.evaluate.base_context import iterator_to_context_set, ContextSet, \
|
||||
NO_CONTEXTS
|
||||
from jedi.evaluate.context import LazyKnownContexts
|
||||
from jedi.evaluate.lazy_context import LazyKnownContexts
|
||||
|
||||
|
||||
DOCSTRING_PARAM_PATTERNS = [
|
||||
|
||||
@@ -5,7 +5,8 @@ from jedi import debug
|
||||
from jedi.evaluate.utils import PushBackIterator
|
||||
from parso.python import tree
|
||||
from jedi.evaluate import analysis
|
||||
from jedi.evaluate import context
|
||||
from jedi.evaluate.lazy_context import LazyKnownContext, LazyKnownContexts, \
|
||||
LazyTreeContext, LazyUnknownContext, get_merged_lazy_context
|
||||
from jedi.evaluate import docstrings
|
||||
from jedi.evaluate import pep0484
|
||||
from jedi.evaluate.filters import ParamName
|
||||
@@ -14,7 +15,7 @@ from jedi.evaluate.context import iterable
|
||||
|
||||
|
||||
def add_argument_issue(parent_context, error_name, lazy_context, message):
|
||||
if isinstance(lazy_context, context.LazyTreeContext):
|
||||
if isinstance(lazy_context, LazyTreeContext):
|
||||
node = lazy_context.data
|
||||
if node.parent.type == 'argument':
|
||||
node = node.parent
|
||||
@@ -141,7 +142,7 @@ class TreeArguments(AbstractArguments):
|
||||
for values in list(zip_longest(*iterators)):
|
||||
# TODO zip_longest yields None, that means this would raise
|
||||
# an exception?
|
||||
yield None, context.get_merged_lazy_context(
|
||||
yield None, get_merged_lazy_context(
|
||||
[v for v in values if v is not None]
|
||||
)
|
||||
elif star_count == 2:
|
||||
@@ -153,14 +154,14 @@ class TreeArguments(AbstractArguments):
|
||||
if el.type == 'argument':
|
||||
c = el.children
|
||||
if len(c) == 3: # Keyword argument.
|
||||
named_args.append((c[0].value, context.LazyTreeContext(self.context, c[2]),))
|
||||
named_args.append((c[0].value, LazyTreeContext(self.context, c[2]),))
|
||||
else: # Generator comprehension.
|
||||
# Include the brackets with the parent.
|
||||
comp = iterable.GeneratorComprehension(
|
||||
self._evaluator, self.context, self.argument_node.parent)
|
||||
yield None, context.LazyKnownContext(comp)
|
||||
yield None, LazyKnownContext(comp)
|
||||
else:
|
||||
yield None, context.LazyTreeContext(self.context, el)
|
||||
yield None, LazyTreeContext(self.context, el)
|
||||
|
||||
# Reordering var_args is necessary, because star args sometimes appear
|
||||
# after named argument, but in the actual order it's prepended.
|
||||
@@ -217,7 +218,7 @@ class ValuesArguments(AbstractArguments):
|
||||
|
||||
def unpack(self, funcdef=None):
|
||||
for values in self._values_list:
|
||||
yield None, context.LazyKnownContexts(values)
|
||||
yield None, LazyKnownContexts(values)
|
||||
|
||||
def get_calling_nodes(self):
|
||||
return []
|
||||
@@ -307,30 +308,30 @@ def get_params(execution_context, var_args):
|
||||
break
|
||||
lazy_context_list.append(argument)
|
||||
seq = iterable.FakeSequence(execution_context.evaluator, 'tuple', lazy_context_list)
|
||||
result_arg = context.LazyKnownContext(seq)
|
||||
result_arg = LazyKnownContext(seq)
|
||||
elif param.star_count == 2:
|
||||
# **kwargs param
|
||||
dct = iterable.FakeDict(execution_context.evaluator, dict(non_matching_keys))
|
||||
result_arg = context.LazyKnownContext(dct)
|
||||
result_arg = LazyKnownContext(dct)
|
||||
non_matching_keys = {}
|
||||
else:
|
||||
# normal param
|
||||
if argument is None:
|
||||
# No value: Return an empty container
|
||||
if param.default is None:
|
||||
result_arg = context.LazyUnknownContext()
|
||||
result_arg = LazyUnknownContext()
|
||||
if not keys_only:
|
||||
for node in var_args.get_calling_nodes():
|
||||
m = _error_argument_count(funcdef, len(unpacked_va))
|
||||
analysis.add(parent_context, 'type-error-too-few-arguments',
|
||||
node, message=m)
|
||||
else:
|
||||
result_arg = context.LazyTreeContext(parent_context, param.default)
|
||||
result_arg = LazyTreeContext(parent_context, param.default)
|
||||
else:
|
||||
result_arg = argument
|
||||
|
||||
result_params.append(ExecutedParam(execution_context, param, result_arg))
|
||||
if not isinstance(result_arg, context.LazyUnknownContext):
|
||||
if not isinstance(result_arg, LazyUnknownContext):
|
||||
keys_used[param.name.value] = result_params[-1]
|
||||
|
||||
if keys_only:
|
||||
@@ -414,17 +415,17 @@ def _error_argument_count(funcdef, actual_count):
|
||||
|
||||
def _create_default_param(execution_context, param):
|
||||
if param.star_count == 1:
|
||||
result_arg = context.LazyKnownContext(
|
||||
result_arg = LazyKnownContext(
|
||||
iterable.FakeSequence(execution_context.evaluator, 'tuple', [])
|
||||
)
|
||||
elif param.star_count == 2:
|
||||
result_arg = context.LazyKnownContext(
|
||||
result_arg = LazyKnownContext(
|
||||
iterable.FakeDict(execution_context.evaluator, {})
|
||||
)
|
||||
elif param.default is None:
|
||||
result_arg = context.LazyUnknownContext()
|
||||
result_arg = LazyUnknownContext()
|
||||
else:
|
||||
result_arg = context.LazyTreeContext(execution_context.parent_context, param.default)
|
||||
result_arg = LazyTreeContext(execution_context.parent_context, param.default)
|
||||
return ExecutedParam(execution_context, param, result_arg)
|
||||
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ from parso.python import tree
|
||||
from jedi.evaluate.cache import evaluator_method_cache
|
||||
from jedi.evaluate import compiled
|
||||
from jedi.evaluate.base_context import NO_CONTEXTS, ContextSet
|
||||
from jedi.evaluate.context import LazyTreeContext
|
||||
from jedi.evaluate.lazy_context import LazyTreeContext
|
||||
from jedi.evaluate.context import ModuleContext
|
||||
from jedi import debug
|
||||
from jedi import _compatibility
|
||||
|
||||
@@ -21,8 +21,9 @@ from jedi.evaluate.context.instance import InstanceFunctionExecution, \
|
||||
AnonymousInstanceFunctionExecution
|
||||
from jedi.evaluate.base_context import ContextualizedNode, \
|
||||
NO_CONTEXTS, ContextSet
|
||||
from jedi.evaluate.context import ClassContext, ModuleContext, LazyTreeContext
|
||||
from jedi.evaluate.context import ClassContext, ModuleContext
|
||||
from jedi.evaluate.context import iterable
|
||||
from jedi.evaluate.lazy_context import LazyTreeContext
|
||||
from jedi.evaluate.syntax_tree import is_string
|
||||
|
||||
# Now this is all part of fake tuples in Jedi. However super doesn't work on
|
||||
|
||||
Reference in New Issue
Block a user