forked from VimPlug/jedi
Start getting inheritance working with e.g. typing.Iterable
This commit is contained in:
@@ -221,10 +221,11 @@ class ClassContext(use_metaclass(CachedMetaClass, TreeContext)):
|
|||||||
return ContextName(self, self.tree_node.name)
|
return ContextName(self, self.tree_node.name)
|
||||||
|
|
||||||
def py__getitem__(self, index_context_set, contextualized_node):
|
def py__getitem__(self, index_context_set, contextualized_node):
|
||||||
print(self.parent_context.__class__.__name__)
|
from jedi.evaluate.context.typing import TypingClassMixin
|
||||||
for cls in list(self.py__mro__()):
|
for cls in self.py__mro__():
|
||||||
pass
|
if isinstance(cls, TypingClassMixin):
|
||||||
print('ha', self, list(self.py__mro__()))
|
#print('ha', self, list(self.py__mro__()))
|
||||||
|
# TODO get the right classes.
|
||||||
|
return ContextSet(self)
|
||||||
|
|
||||||
#print(index_context_set)
|
|
||||||
return super(ClassContext, self).py__getitem__(index_context_set, contextualized_node)
|
return super(ClassContext, self).py__getitem__(index_context_set, contextualized_node)
|
||||||
|
|||||||
@@ -110,29 +110,29 @@ class _WithIndexBase(_BaseTypingContext):
|
|||||||
|
|
||||||
class TypingContextWithIndex(_WithIndexBase):
|
class TypingContextWithIndex(_WithIndexBase):
|
||||||
def execute_annotation(self):
|
def execute_annotation(self):
|
||||||
name = self._name
|
string_name = self._name.string_name
|
||||||
if name in _TYPE_ALIAS_TYPES:
|
if string_name in _TYPE_ALIAS_TYPES:
|
||||||
debug.warning('type aliases are not yet implemented')
|
debug.warning('type aliases are not yet implemented')
|
||||||
return NO_CONTEXTS
|
return NO_CONTEXTS
|
||||||
|
|
||||||
if name == 'Union':
|
if string_name == 'Union':
|
||||||
# This is kind of a special case, because we have Unions (in Jedi
|
# This is kind of a special case, because we have Unions (in Jedi
|
||||||
# ContextSets).
|
# ContextSets).
|
||||||
return self._execute_annotations_for_all_indexes()
|
return self._execute_annotations_for_all_indexes()
|
||||||
elif name == 'Optional':
|
elif string_name == 'Optional':
|
||||||
# Optional is basically just saying it's either None or the actual
|
# Optional is basically just saying it's either None or the actual
|
||||||
# type.
|
# type.
|
||||||
return ContextSet(self._context) \
|
return ContextSet(self._context) \
|
||||||
| ContextSet(builtin_from_name(self.evaluator, u'None'))
|
| ContextSet(builtin_from_name(self.evaluator, u'None'))
|
||||||
elif name == 'Type':
|
elif string_name == 'Type':
|
||||||
# The type is actually already given in the index_context
|
# The type is actually already given in the index_context
|
||||||
return ContextSet(self._index_context)
|
return ContextSet(self._index_context)
|
||||||
elif name == 'ClassVar':
|
elif string_name == 'ClassVar':
|
||||||
# For now don't do anything here, ClassVars are always used.
|
# For now don't do anything here, ClassVars are always used.
|
||||||
return self._context.execute_annotation()
|
return self._context.execute_annotation()
|
||||||
|
|
||||||
cls = globals()[name]
|
cls = globals()[string_name]
|
||||||
return ContextSet(cls(name, self._context, self._index_context))
|
return ContextSet(cls(self._name, self._index_context))
|
||||||
|
|
||||||
|
|
||||||
class TypingContext(_BaseTypingContext):
|
class TypingContext(_BaseTypingContext):
|
||||||
@@ -147,6 +147,14 @@ class TypingContext(_BaseTypingContext):
|
|||||||
|
|
||||||
|
|
||||||
class TypingClassMixin(object):
|
class TypingClassMixin(object):
|
||||||
|
@property
|
||||||
|
def tree_node(self):
|
||||||
|
return self.name.tree_name
|
||||||
|
|
||||||
|
def get_filters(self, *args, **kwargs):
|
||||||
|
# TODO this is obviously wrong.
|
||||||
|
return iter([])
|
||||||
|
|
||||||
def py__mro__(self):
|
def py__mro__(self):
|
||||||
return (self,)
|
return (self,)
|
||||||
|
|
||||||
@@ -168,8 +176,9 @@ def _iter_over_arguments(maybe_tuple_context):
|
|||||||
|
|
||||||
|
|
||||||
class _ContainerBase(_WithIndexBase):
|
class _ContainerBase(_WithIndexBase):
|
||||||
def get_filters(self):
|
def get_filters(self, *args, **kwargs):
|
||||||
pass
|
# TODO this is obviously wrong.
|
||||||
|
return iter([])
|
||||||
|
|
||||||
def _get_getitem_contexts(self, index):
|
def _get_getitem_contexts(self, index):
|
||||||
for i, contexts in enumerate(_iter_over_arguments(self._index_context)):
|
for i, contexts in enumerate(_iter_over_arguments(self._index_context)):
|
||||||
|
|||||||
Reference in New Issue
Block a user