forked from VimPlug/jedi
Define generics from a different function
This commit is contained in:
@@ -279,8 +279,7 @@ class TreeInstance(AbstractInstanceContext):
|
||||
continue
|
||||
|
||||
all_annotations = pep0484.py__annotations__(execution.tree_node)
|
||||
defined = pep0484.define_type_vars(
|
||||
self.class_context,
|
||||
defined = self.class_context.define_generics(
|
||||
pep0484.infer_type_vars_for_execution(execution, all_annotations),
|
||||
)
|
||||
debug.dbg('Inferred instance context as %s', defined, color='BLUE')
|
||||
|
||||
@@ -529,6 +529,12 @@ class FakeDict(_DictMixin, _FakeArray):
|
||||
def _dict_values(self):
|
||||
return ContextSet.from_sets(lazy_context.infer() for lazy_context in self._dct.values())
|
||||
|
||||
def _dict_keys(self):
|
||||
return ContextSet.from_sets(lazy_context.infer() for lazy_context in self.py__iter__())
|
||||
|
||||
def get_mapping_item_contexts(self):
|
||||
return self._dict_keys(), self._dict_values()
|
||||
|
||||
def exact_key_items(self):
|
||||
return self._dct.items()
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ from jedi.evaluate.filters import ParserTreeFilter, TreeNameDefinition, \
|
||||
ContextName
|
||||
from jedi.evaluate.arguments import unpack_arglist
|
||||
from jedi.evaluate.base_context import ContextSet, iterator_to_context_set, \
|
||||
TreeContext
|
||||
TreeContext, NO_CONTEXTS
|
||||
|
||||
|
||||
def apply_py__get__(context, base_context):
|
||||
@@ -274,3 +274,19 @@ class ClassContext(use_metaclass(CachedMetaClass, TreeContext)):
|
||||
)
|
||||
for index_context in index_context_set
|
||||
)
|
||||
|
||||
def define_generics(self, type_var_dict):
|
||||
from jedi.evaluate.context.typing import AnnotatedSubClass
|
||||
|
||||
def remap_type_vars():
|
||||
for type_var in self.list_type_vars():
|
||||
yield type_var_dict.get(type_var.py__name__(), NO_CONTEXTS)
|
||||
|
||||
if type_var_dict:
|
||||
return AnnotatedSubClass(
|
||||
self.evaluator,
|
||||
self.parent_context,
|
||||
self.tree_node,
|
||||
given_types=tuple(remap_type_vars())
|
||||
)
|
||||
return self
|
||||
|
||||
Reference in New Issue
Block a user