forked from VimPlug/jedi
Add a ContextSet.
This is not bug free yet, but it's going to be a good abstraction for a lot of small things.
This commit is contained in:
@@ -15,6 +15,7 @@ from jedi.evaluate.filters import AbstractFilter, AbstractNameDefinition, \
|
||||
ContextNameMixin
|
||||
from jedi.evaluate.context import Context, LazyKnownContext
|
||||
from jedi.evaluate.compiled.getattr_static import getattr_static
|
||||
from jedi.common import ContextSet
|
||||
from . import fake
|
||||
|
||||
|
||||
@@ -83,9 +84,9 @@ class CompiledObject(Context):
|
||||
def py__call__(self, params):
|
||||
if inspect.isclass(self.obj):
|
||||
from jedi.evaluate.instance import CompiledInstance
|
||||
return set([CompiledInstance(self.evaluator, self.parent_context, self, params)])
|
||||
return ContextSet(CompiledInstance(self.evaluator, self.parent_context, self, params))
|
||||
else:
|
||||
return set(self._execute_function(params))
|
||||
return ContextSet.from_iterable(self._execute_function(params))
|
||||
|
||||
@CheckAttribute
|
||||
def py__class__(self):
|
||||
@@ -221,9 +222,9 @@ class CompiledObject(Context):
|
||||
def py__getitem__(self, index):
|
||||
if type(self.obj) not in (str, list, tuple, unicode, bytes, bytearray, dict):
|
||||
# Get rid of side effects, we won't call custom `__getitem__`s.
|
||||
return set()
|
||||
return ContextSet()
|
||||
|
||||
return set([create(self.evaluator, self.obj[index])])
|
||||
return ContextSet(create(self.evaluator, self.obj[index]))
|
||||
|
||||
@CheckAttribute
|
||||
def py__iter__(self):
|
||||
@@ -278,7 +279,7 @@ class CompiledObject(Context):
|
||||
return [] # Builtins don't have imports
|
||||
|
||||
def dict_values(self):
|
||||
return set(create(self.evaluator, v) for v in self.obj.values())
|
||||
return ContextSet(create(self.evaluator, v) for v in self.obj.values())
|
||||
|
||||
|
||||
class CompiledName(AbstractNameDefinition):
|
||||
@@ -301,7 +302,9 @@ class CompiledName(AbstractNameDefinition):
|
||||
@underscore_memoization
|
||||
def infer(self):
|
||||
module = self.parent_context.get_root_context()
|
||||
return [_create_from_name(self._evaluator, module, self.parent_context, self.string_name)]
|
||||
return ContextSet(_create_from_name(
|
||||
self._evaluator, module, self.parent_context, self.string_name
|
||||
))
|
||||
|
||||
|
||||
class SignatureParamName(AbstractNameDefinition):
|
||||
@@ -318,13 +321,13 @@ class SignatureParamName(AbstractNameDefinition):
|
||||
def infer(self):
|
||||
p = self._signature_param
|
||||
evaluator = self.parent_context.evaluator
|
||||
types = set()
|
||||
contexts = ContextSet()
|
||||
if p.default is not p.empty:
|
||||
types.add(create(evaluator, p.default))
|
||||
contexts = ContextSet(create(evaluator, p.default))
|
||||
if p.annotation is not p.empty:
|
||||
annotation = create(evaluator, p.annotation)
|
||||
types |= annotation.execute_evaluated()
|
||||
return types
|
||||
contexts |= annotation.execute_evaluated()
|
||||
return contexts
|
||||
|
||||
|
||||
class UnresolvableParamName(AbstractNameDefinition):
|
||||
@@ -335,7 +338,7 @@ class UnresolvableParamName(AbstractNameDefinition):
|
||||
self.string_name = name
|
||||
|
||||
def infer(self):
|
||||
return set()
|
||||
return ContextSet()
|
||||
|
||||
|
||||
class CompiledContextName(ContextNameMixin, AbstractNameDefinition):
|
||||
@@ -356,7 +359,7 @@ class EmptyCompiledName(AbstractNameDefinition):
|
||||
self.string_name = name
|
||||
|
||||
def infer(self):
|
||||
return []
|
||||
return ContextSet()
|
||||
|
||||
|
||||
class CompiledObjectFilter(AbstractFilter):
|
||||
|
||||
Reference in New Issue
Block a user