forked from VimPlug/jedi
Use ContextSet closer to they way how Python's set works
This commit is contained in:
@@ -34,7 +34,7 @@ class LambdaName(AbstractNameDefinition):
|
||||
return self._lambda_context.tree_node.start_pos
|
||||
|
||||
def infer(self):
|
||||
return ContextSet(self._lambda_context)
|
||||
return ContextSet([self._lambda_context])
|
||||
|
||||
|
||||
class AbstractFunction(TreeContext):
|
||||
@@ -195,7 +195,7 @@ class FunctionExecutionContext(TreeContext):
|
||||
children = r.children
|
||||
except AttributeError:
|
||||
ctx = compiled.builtin_from_name(self.evaluator, u'None')
|
||||
context_set |= ContextSet(ctx)
|
||||
context_set |= ContextSet([ctx])
|
||||
else:
|
||||
context_set |= self.eval_node(children[1])
|
||||
if check is flow_analysis.REACHABLE:
|
||||
@@ -341,7 +341,7 @@ class FunctionExecutionContext(TreeContext):
|
||||
).execute_annotation()
|
||||
else:
|
||||
if is_generator:
|
||||
return ContextSet(iterable.Generator(evaluator, self))
|
||||
return ContextSet([iterable.Generator(evaluator, self)])
|
||||
else:
|
||||
return self.get_return_values()
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class InstanceExecutedParam(object):
|
||||
self.string_name = self._tree_param.name.value
|
||||
|
||||
def infer(self):
|
||||
return ContextSet(self._instance)
|
||||
return ContextSet([self._instance])
|
||||
|
||||
def matches_signature(self):
|
||||
return True
|
||||
@@ -120,7 +120,7 @@ class AbstractInstanceContext(Context):
|
||||
none_obj = compiled.builtin_from_name(self.evaluator, u'None')
|
||||
return self.execute_function_slots(names, none_obj, obj)
|
||||
else:
|
||||
return ContextSet(self)
|
||||
return ContextSet([self])
|
||||
|
||||
def get_filters(self, search_global=None, until_position=None,
|
||||
origin_scope=None, include_self_names=True):
|
||||
|
||||
@@ -44,7 +44,7 @@ from jedi.parser_utils import get_comp_fors
|
||||
|
||||
class IterableMixin(object):
|
||||
def py__stop_iteration_returns(self):
|
||||
return ContextSet(compiled.builtin_from_name(self.evaluator, u'None'))
|
||||
return ContextSet([compiled.builtin_from_name(self.evaluator, u'None')])
|
||||
|
||||
|
||||
class GeneratorBase(BuiltinOverwrite, IterableMixin):
|
||||
@@ -210,7 +210,7 @@ class Sequence(BuiltinOverwrite, IterableMixin):
|
||||
def py__getitem__(self, index_context_set, contextualized_node):
|
||||
if self.array_type == 'dict':
|
||||
return self._dict_values()
|
||||
return iterate_contexts(ContextSet(self))
|
||||
return iterate_contexts(ContextSet([self]))
|
||||
|
||||
|
||||
class ListComprehension(ComprehensionMixin, Sequence):
|
||||
@@ -218,7 +218,7 @@ class ListComprehension(ComprehensionMixin, Sequence):
|
||||
|
||||
def py__simple_getitem__(self, index):
|
||||
if isinstance(index, slice):
|
||||
return ContextSet(self)
|
||||
return ContextSet([self])
|
||||
|
||||
all_types = list(self.py__iter__())
|
||||
with reraise_getitem_errors(IndexError, TypeError):
|
||||
@@ -254,7 +254,7 @@ class DictComprehension(ComprehensionMixin, Sequence):
|
||||
@publish_method('values')
|
||||
def _imitate_values(self):
|
||||
lazy_context = LazyKnownContexts(self._dict_values())
|
||||
return ContextSet(FakeSequence(self.evaluator, u'list', [lazy_context]))
|
||||
return ContextSet([FakeSequence(self.evaluator, u'list', [lazy_context])])
|
||||
|
||||
@publish_method('items')
|
||||
def _imitate_items(self):
|
||||
@@ -270,7 +270,7 @@ class DictComprehension(ComprehensionMixin, Sequence):
|
||||
for key, value in self._iterate()
|
||||
]
|
||||
|
||||
return ContextSet(FakeSequence(self.evaluator, u'list', lazy_contexts))
|
||||
return ContextSet([FakeSequence(self.evaluator, u'list', lazy_contexts)])
|
||||
|
||||
|
||||
class GeneratorComprehension(ComprehensionMixin, GeneratorBase):
|
||||
@@ -310,7 +310,7 @@ class SequenceLiteralContext(Sequence):
|
||||
raise SimpleGetItemNotFound('No key found in dictionary %s.' % self)
|
||||
|
||||
if isinstance(index, slice):
|
||||
return ContextSet(self)
|
||||
return ContextSet([self])
|
||||
else:
|
||||
with reraise_getitem_errors(TypeError, KeyError, IndexError):
|
||||
node = self.get_tree_entries()[index]
|
||||
@@ -323,7 +323,7 @@ class SequenceLiteralContext(Sequence):
|
||||
"""
|
||||
if self.array_type == u'dict':
|
||||
# Get keys.
|
||||
types = ContextSet()
|
||||
types = NO_CONTEXTS
|
||||
for k, _ in self.get_tree_entries():
|
||||
types |= self._defining_context.eval_node(k)
|
||||
# We don't know which dict index comes first, therefore always
|
||||
@@ -417,7 +417,7 @@ class DictLiteralContext(SequenceLiteralContext):
|
||||
@publish_method('values')
|
||||
def _imitate_values(self):
|
||||
lazy_context = LazyKnownContexts(self._dict_values())
|
||||
return ContextSet(FakeSequence(self.evaluator, u'list', [lazy_context]))
|
||||
return ContextSet([FakeSequence(self.evaluator, u'list', [lazy_context])])
|
||||
|
||||
@publish_method('items')
|
||||
def _imitate_items(self):
|
||||
@@ -429,7 +429,7 @@ class DictLiteralContext(SequenceLiteralContext):
|
||||
)) for key_node, value_node in self.get_tree_entries()
|
||||
]
|
||||
|
||||
return ContextSet(FakeSequence(self.evaluator, u'list', lazy_contexts))
|
||||
return ContextSet([FakeSequence(self.evaluator, u'list', lazy_contexts)])
|
||||
|
||||
def _dict_keys(self):
|
||||
return ContextSet.from_sets(
|
||||
@@ -503,10 +503,10 @@ class FakeDict(_FakeArray):
|
||||
|
||||
@publish_method('values')
|
||||
def _values(self):
|
||||
return ContextSet(FakeSequence(
|
||||
return ContextSet([FakeSequence(
|
||||
self.evaluator, u'tuple',
|
||||
[LazyKnownContexts(self._dict_values())]
|
||||
))
|
||||
)])
|
||||
|
||||
def _dict_values(self):
|
||||
return ContextSet.from_sets(lazy_context.infer() for lazy_context in self._dct.values())
|
||||
@@ -601,7 +601,7 @@ def _check_array_additions(context, sequence):
|
||||
module_context = context.get_root_context()
|
||||
if not settings.dynamic_array_additions or isinstance(module_context, compiled.CompiledObject):
|
||||
debug.dbg('Dynamic array search aborted.', color='MAGENTA')
|
||||
return ContextSet()
|
||||
return NO_CONTEXTS
|
||||
|
||||
def find_additions(context, arglist, add_name):
|
||||
params = list(arguments.TreeArguments(context.evaluator, context, arglist).unpack())
|
||||
@@ -673,7 +673,7 @@ def get_dynamic_array_instance(instance, arguments):
|
||||
"""Used for set() and list() instances."""
|
||||
ai = _ArrayInstance(instance, arguments)
|
||||
from jedi.evaluate import arguments
|
||||
return arguments.ValuesArguments([ContextSet(ai)])
|
||||
return arguments.ValuesArguments([ContextSet([ai])])
|
||||
|
||||
|
||||
class _ArrayInstance(object):
|
||||
|
||||
@@ -197,7 +197,7 @@ class ClassContext(use_metaclass(CachedMetaClass, TreeContext)):
|
||||
|
||||
def py__call__(self, arguments):
|
||||
from jedi.evaluate.context import TreeInstance
|
||||
return ContextSet(TreeInstance(self.evaluator, self.parent_context, self, arguments))
|
||||
return ContextSet([TreeInstance(self.evaluator, self.parent_context, self, arguments)])
|
||||
|
||||
def py__class__(self):
|
||||
return compiled.builtin_from_name(self.evaluator, u'type')
|
||||
@@ -263,8 +263,8 @@ class ClassContext(use_metaclass(CachedMetaClass, TreeContext)):
|
||||
def py__getitem__(self, index_context_set, contextualized_node):
|
||||
from jedi.evaluate.context.typing import AnnotatedClass
|
||||
if not index_context_set:
|
||||
return ContextSet(self)
|
||||
return ContextSet.from_iterable(
|
||||
return ContextSet([self])
|
||||
return ContextSet(
|
||||
AnnotatedClass(
|
||||
self.evaluator,
|
||||
self.parent_context,
|
||||
|
||||
@@ -39,7 +39,7 @@ class TypingName(AbstractTreeName):
|
||||
self._context = context
|
||||
|
||||
def infer(self):
|
||||
return ContextSet(self._context)
|
||||
return ContextSet([self._context])
|
||||
|
||||
|
||||
class _BaseTypingContext(Context):
|
||||
@@ -72,7 +72,7 @@ class _BaseTypingContext(Context):
|
||||
|
||||
class TypingModuleName(NameWrapper):
|
||||
def infer(self):
|
||||
return ContextSet.from_iterable(self._remap())
|
||||
return ContextSet(self._remap())
|
||||
|
||||
def _remap(self):
|
||||
name = self.string_name
|
||||
@@ -157,22 +157,22 @@ class TypingContextWithIndex(_WithIndexBase):
|
||||
# Optional is basically just saying it's either None or the actual
|
||||
# type.
|
||||
return self._execute_annotations_for_all_indexes() \
|
||||
| ContextSet(builtin_from_name(self.evaluator, u'None'))
|
||||
| ContextSet([builtin_from_name(self.evaluator, u'None')])
|
||||
elif string_name == 'Type':
|
||||
# The type is actually already given in the index_context
|
||||
return ContextSet(self._index_context)
|
||||
return ContextSet([self._index_context])
|
||||
elif string_name == 'ClassVar':
|
||||
# For now don't do anything here, ClassVars are always used.
|
||||
return self._index_context.execute_annotation()
|
||||
|
||||
cls = globals()[string_name]
|
||||
return ContextSet(cls(
|
||||
return ContextSet([cls(
|
||||
self.evaluator,
|
||||
self.parent_context,
|
||||
self._tree_name,
|
||||
self._index_context,
|
||||
self._context_of_index
|
||||
))
|
||||
)])
|
||||
|
||||
|
||||
class TypingContext(_BaseTypingContext):
|
||||
@@ -180,7 +180,7 @@ class TypingContext(_BaseTypingContext):
|
||||
py__simple_getitem__ = None
|
||||
|
||||
def py__getitem__(self, index_context_set, contextualized_node):
|
||||
return ContextSet.from_iterable(
|
||||
return ContextSet(
|
||||
self.index_class.create_cached(
|
||||
self.evaluator,
|
||||
self.parent_context,
|
||||
@@ -210,7 +210,7 @@ def _iter_over_arguments(maybe_tuple_context, defining_context):
|
||||
for lazy_context in maybe_tuple_context.py__iter__():
|
||||
yield lazy_context.infer()
|
||||
else:
|
||||
yield ContextSet(maybe_tuple_context)
|
||||
yield ContextSet([maybe_tuple_context])
|
||||
|
||||
def resolve_forward_references(context_set):
|
||||
for context in context_set:
|
||||
@@ -224,7 +224,7 @@ def _iter_over_arguments(maybe_tuple_context, defining_context):
|
||||
yield context
|
||||
|
||||
for context_set in iterate():
|
||||
yield ContextSet.from_iterable(resolve_forward_references(context_set))
|
||||
yield ContextSet(resolve_forward_references(context_set))
|
||||
|
||||
|
||||
class TypeAlias(HelperContextMixin):
|
||||
@@ -341,13 +341,13 @@ class TypeVarClass(_BaseTypingContext):
|
||||
debug.warning('Found a variable without a name %s', arguments)
|
||||
return NO_CONTEXTS
|
||||
|
||||
return ContextSet(TypeVar.create_cached(
|
||||
return ContextSet([TypeVar.create_cached(
|
||||
self.evaluator,
|
||||
self.parent_context,
|
||||
self._tree_name,
|
||||
var_name,
|
||||
unpacked
|
||||
))
|
||||
)])
|
||||
|
||||
def _find_string_name(self, lazy_context):
|
||||
if lazy_context is None:
|
||||
@@ -451,7 +451,7 @@ class BoundTypeVarName(AbstractNameDefinition):
|
||||
yield constraint
|
||||
else:
|
||||
yield context
|
||||
return ContextSet.from_iterable(iter_())
|
||||
return ContextSet(iter_())
|
||||
|
||||
def py__name__(self):
|
||||
return self._type_var.py__name__()
|
||||
@@ -530,7 +530,7 @@ class _AbstractAnnotatedClass(ClassContext):
|
||||
|
||||
def py__call__(self, arguments):
|
||||
instance, = super(_AbstractAnnotatedClass, self).py__call__(arguments)
|
||||
return ContextSet(InstanceWrapper(instance))
|
||||
return ContextSet([InstanceWrapper(instance)])
|
||||
|
||||
def get_given_types(self):
|
||||
raise NotImplementedError
|
||||
@@ -590,7 +590,7 @@ class LazyAnnotatedBaseClass(object):
|
||||
def _remap_type_vars(self, base):
|
||||
filter = self._class_context.get_type_var_filter()
|
||||
for type_var_set in base.get_given_types():
|
||||
new = ContextSet()
|
||||
new = NO_CONTEXTS
|
||||
for type_var in type_var_set:
|
||||
if isinstance(type_var, TypeVar):
|
||||
names = filter.get(type_var.py__name__())
|
||||
@@ -601,7 +601,7 @@ class LazyAnnotatedBaseClass(object):
|
||||
# Mostly will be type vars, except if in some cases
|
||||
# a concrete type will already be there. In that
|
||||
# case just add it to the context set.
|
||||
new |= ContextSet(type_var)
|
||||
new |= ContextSet([type_var])
|
||||
yield new
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user