mirror of
https://github.com/davidhalter/jedi.git
synced 2026-01-09 05:22:19 +08:00
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)
|
||||
|
||||
def py__getitem__(self, index_context_set, contextualized_node):
|
||||
print(self.parent_context.__class__.__name__)
|
||||
for cls in list(self.py__mro__()):
|
||||
pass
|
||||
print('ha', self, list(self.py__mro__()))
|
||||
from jedi.evaluate.context.typing import TypingClassMixin
|
||||
for cls in self.py__mro__():
|
||||
if isinstance(cls, TypingClassMixin):
|
||||
#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)
|
||||
|
||||
@@ -110,29 +110,29 @@ class _WithIndexBase(_BaseTypingContext):
|
||||
|
||||
class TypingContextWithIndex(_WithIndexBase):
|
||||
def execute_annotation(self):
|
||||
name = self._name
|
||||
if name in _TYPE_ALIAS_TYPES:
|
||||
string_name = self._name.string_name
|
||||
if string_name in _TYPE_ALIAS_TYPES:
|
||||
debug.warning('type aliases are not yet implemented')
|
||||
return NO_CONTEXTS
|
||||
|
||||
if name == 'Union':
|
||||
if string_name == 'Union':
|
||||
# This is kind of a special case, because we have Unions (in Jedi
|
||||
# ContextSets).
|
||||
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
|
||||
# type.
|
||||
return ContextSet(self._context) \
|
||||
| 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
|
||||
return ContextSet(self._index_context)
|
||||
elif name == 'ClassVar':
|
||||
elif string_name == 'ClassVar':
|
||||
# For now don't do anything here, ClassVars are always used.
|
||||
return self._context.execute_annotation()
|
||||
|
||||
cls = globals()[name]
|
||||
return ContextSet(cls(name, self._context, self._index_context))
|
||||
cls = globals()[string_name]
|
||||
return ContextSet(cls(self._name, self._index_context))
|
||||
|
||||
|
||||
class TypingContext(_BaseTypingContext):
|
||||
@@ -147,6 +147,14 @@ class TypingContext(_BaseTypingContext):
|
||||
|
||||
|
||||
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):
|
||||
return (self,)
|
||||
|
||||
@@ -168,8 +176,9 @@ def _iter_over_arguments(maybe_tuple_context):
|
||||
|
||||
|
||||
class _ContainerBase(_WithIndexBase):
|
||||
def get_filters(self):
|
||||
pass
|
||||
def get_filters(self, *args, **kwargs):
|
||||
# TODO this is obviously wrong.
|
||||
return iter([])
|
||||
|
||||
def _get_getitem_contexts(self, index):
|
||||
for i, contexts in enumerate(_iter_over_arguments(self._index_context)):
|
||||
|
||||
Reference in New Issue
Block a user