More fixes to *args type inference.

This commit is contained in:
Dave Halter
2016-10-30 01:35:36 +02:00
parent 3cce530ef4
commit c537d360f3
5 changed files with 110 additions and 97 deletions

View File

@@ -1,3 +1,4 @@
from jedi.common import unite
class Context(object):
type = None # TODO remove
@@ -35,3 +36,56 @@ class FlowContext(TreeContext):
def get_parent_flow_context(self):
if 1:
return self.parent_context
class AbstractLazyContext(object):
def __init__(self, data):
self._data = data
def __repr__(self):
return '<%s: %s>' % (self.__class__.__name__, self._data)
def infer(self):
raise NotImplementedError
class LazyKnownContext(AbstractLazyContext):
"""data is a context."""
def infer(self):
return set([self._data])
class LazyKnownContexts(AbstractLazyContext):
"""data is a set of contexts."""
def infer(self):
return self._data
class LazyUnknownContext(AbstractLazyContext):
def __init__(self):
super(LazyUnknownContext, self).__init__(None)
def infer(self):
return set()
class LazyTreeContext(AbstractLazyContext):
def __init__(self, context, node):
self._context = context
self._data = node
def infer(self):
return self._context.eval_node(self._data)
def get_merged_lazy_context(lazy_contexts):
if len(lazy_contexts) > 1:
return MergedLazyContexts(lazy_contexts)
else:
return lazy_contexts[0]
class MergedLazyContexts(AbstractLazyContext):
"""data is a list of lazy contexts."""
def infer(self):
return unite(l.infer() for l in self._data)