1
0
forked from VimPlug/jedi

Rename AnnotatedClass to GenericClass

This commit is contained in:
Dave Halter
2019-05-27 21:21:42 +02:00
parent d2355ea53b
commit 1002acf907
5 changed files with 17 additions and 17 deletions

View File

@@ -333,7 +333,7 @@ class FunctionExecutionContext(TreeContext):
evaluator = self.evaluator evaluator = self.evaluator
is_coroutine = self.tree_node.parent.type in ('async_stmt', 'async_funcdef') is_coroutine = self.tree_node.parent.type in ('async_stmt', 'async_funcdef')
is_generator = bool(get_yield_exprs(evaluator, self.tree_node)) is_generator = bool(get_yield_exprs(evaluator, self.tree_node))
from jedi.evaluate.gradual.typing import AnnotatedSubClass from jedi.evaluate.gradual.typing import GenericClass
if is_coroutine: if is_coroutine:
if is_generator: if is_generator:
@@ -347,7 +347,7 @@ class FunctionExecutionContext(TreeContext):
generics = (yield_contexts.py__class__(), NO_CONTEXTS) generics = (yield_contexts.py__class__(), NO_CONTEXTS)
return ContextSet( return ContextSet(
# In Python 3.6 AsyncGenerator is still a class. # In Python 3.6 AsyncGenerator is still a class.
AnnotatedSubClass(c, generics) GenericClass(c, generics)
for c in async_generator_classes for c in async_generator_classes
).execute_annotation() ).execute_annotation()
else: else:
@@ -358,7 +358,7 @@ class FunctionExecutionContext(TreeContext):
# Only the first generic is relevant. # Only the first generic is relevant.
generics = (return_contexts.py__class__(), NO_CONTEXTS, NO_CONTEXTS) generics = (return_contexts.py__class__(), NO_CONTEXTS, NO_CONTEXTS)
return ContextSet( return ContextSet(
AnnotatedSubClass(c, generics) for c in async_classes GenericClass(c, generics) for c in async_classes
).execute_annotation() ).execute_annotation()
else: else:
if is_generator: if is_generator:

View File

@@ -208,10 +208,10 @@ class Sequence(BuiltinOverwrite, IterableMixin):
@memoize_method @memoize_method
def get_object(self): def get_object(self):
from jedi.evaluate.gradual.typing import AnnotatedSubClass from jedi.evaluate.gradual.typing import GenericClass
klass = compiled.builtin_from_name(self.evaluator, self.array_type) klass = compiled.builtin_from_name(self.evaluator, self.array_type)
# TODO is this execute annotation wrong? it returns a context set?! # TODO is this execute annotation wrong? it returns a context set?!
return AnnotatedSubClass(klass, self._get_generics()).execute_annotation() return GenericClass(klass, self._get_generics()).execute_annotation()
def py__bool__(self): def py__bool__(self):
return None # We don't know the length, because of appends. return None # We don't know the length, because of appends.

View File

@@ -243,11 +243,11 @@ class ClassContext(use_metaclass(CachedMetaClass, ClassMixin, FunctionAndClassBa
)] )]
def py__getitem__(self, index_context_set, contextualized_node): def py__getitem__(self, index_context_set, contextualized_node):
from jedi.evaluate.gradual.typing import AnnotatedClass from jedi.evaluate.gradual.typing import LazyGenericClass
if not index_context_set: if not index_context_set:
return ContextSet([self]) return ContextSet([self])
return ContextSet( return ContextSet(
AnnotatedClass( LazyGenericClass(
self, self,
index_context, index_context,
context_of_index=contextualized_node.context, context_of_index=contextualized_node.context,
@@ -256,7 +256,7 @@ class ClassContext(use_metaclass(CachedMetaClass, ClassMixin, FunctionAndClassBa
) )
def define_generics(self, type_var_dict): def define_generics(self, type_var_dict):
from jedi.evaluate.gradual.typing import AnnotatedSubClass from jedi.evaluate.gradual.typing import GenericClass
def remap_type_vars(): def remap_type_vars():
""" """
@@ -272,7 +272,7 @@ class ClassContext(use_metaclass(CachedMetaClass, ClassMixin, FunctionAndClassBa
yield type_var_dict.get(type_var.py__name__(), NO_CONTEXTS) yield type_var_dict.get(type_var.py__name__(), NO_CONTEXTS)
if type_var_dict: if type_var_dict:
return AnnotatedSubClass( return GenericClass(
self, self,
generics=tuple(remap_type_vars()) generics=tuple(remap_type_vars())
) )

View File

@@ -12,7 +12,7 @@ from parso import ParserSyntaxError, parse
from jedi._compatibility import force_unicode from jedi._compatibility import force_unicode
from jedi.evaluate.cache import evaluator_method_cache from jedi.evaluate.cache import evaluator_method_cache
from jedi.evaluate.base_context import ContextSet, NO_CONTEXTS from jedi.evaluate.base_context import ContextSet, NO_CONTEXTS
from jedi.evaluate.gradual.typing import TypeVar, AnnotatedClass, \ from jedi.evaluate.gradual.typing import TypeVar, LazyGenericClass, \
AbstractAnnotatedClass AbstractAnnotatedClass
from jedi.evaluate.helpers import is_string from jedi.evaluate.helpers import is_string
from jedi import debug from jedi import debug
@@ -274,7 +274,7 @@ def _infer_type_vars(annotation_context, context_set):
type_var_dict = {} type_var_dict = {}
if isinstance(annotation_context, TypeVar): if isinstance(annotation_context, TypeVar):
return {annotation_context.py__name__(): context_set.py__class__()} return {annotation_context.py__name__(): context_set.py__class__()}
elif isinstance(annotation_context, AnnotatedClass): elif isinstance(annotation_context, LazyGenericClass):
name = annotation_context.py__name__() name = annotation_context.py__name__()
if name == 'Iterable': if name == 'Iterable':
given = annotation_context.get_generics() given = annotation_context.get_generics()

View File

@@ -588,7 +588,7 @@ class AbstractAnnotatedClass(ClassMixin, ContextWrapper):
# cached results. # cached results.
return self return self
return AnnotatedSubClass( return GenericClass(
self._wrapped_context, self._wrapped_context,
generics=tuple(new_generics) generics=tuple(new_generics)
) )
@@ -606,9 +606,9 @@ class AbstractAnnotatedClass(ClassMixin, ContextWrapper):
yield LazyAnnotatedBaseClass(self, base) yield LazyAnnotatedBaseClass(self, base)
class AnnotatedClass(AbstractAnnotatedClass): class LazyGenericClass(AbstractAnnotatedClass):
def __init__(self, class_context, index_context, context_of_index): def __init__(self, class_context, index_context, context_of_index):
super(AnnotatedClass, self).__init__(class_context) super(LazyGenericClass, self).__init__(class_context)
self._index_context = index_context self._index_context = index_context
self._context_of_index = context_of_index self._context_of_index = context_of_index
@@ -617,9 +617,9 @@ class AnnotatedClass(AbstractAnnotatedClass):
return list(_iter_over_arguments(self._index_context, self._context_of_index)) return list(_iter_over_arguments(self._index_context, self._context_of_index))
class AnnotatedSubClass(AbstractAnnotatedClass): class GenericClass(AbstractAnnotatedClass):
def __init__(self, class_context, generics): def __init__(self, class_context, generics):
super(AnnotatedSubClass, self).__init__(class_context) super(GenericClass, self).__init__(class_context)
self._generics = generics self._generics = generics
def get_generics(self): def get_generics(self):
@@ -636,7 +636,7 @@ class LazyAnnotatedBaseClass(object):
for base in self._lazy_base_class.infer(): for base in self._lazy_base_class.infer():
if isinstance(base, AbstractAnnotatedClass): if isinstance(base, AbstractAnnotatedClass):
# Here we have to recalculate the given types. # Here we have to recalculate the given types.
yield AnnotatedSubClass.create_cached( yield GenericClass.create_cached(
base.evaluator, base.evaluator,
base._wrapped_context, base._wrapped_context,
tuple(self._remap_type_vars(base)), tuple(self._remap_type_vars(base)),