forked from VimPlug/jedi
implement __getitem__ access for CompiledObject
This commit is contained in:
@@ -93,15 +93,26 @@ class CompiledObject(Base):
|
||||
else:
|
||||
raise KeyError("CompiledObject doesn't have an attribute '%s'." % name)
|
||||
|
||||
def get_index_types(self, mixed_obj):
|
||||
def get_index_types(self, index_types):
|
||||
# If the object doesn't have `__getitem__`, just raise the
|
||||
# AttributeError.
|
||||
self.obj.__getitem__
|
||||
|
||||
result = []
|
||||
from jedi.evaluate import iterable
|
||||
for typ in index_types:
|
||||
if isinstance(typ, iterable.Slice):
|
||||
result.append(self)
|
||||
else:
|
||||
try:
|
||||
self.obj[mixed_obj]
|
||||
new = self.obj[typ.obj]
|
||||
except (KeyError, IndexError):
|
||||
raise AttributeError()
|
||||
pass
|
||||
else:
|
||||
result.append(CompiledObject(new))
|
||||
if not result:
|
||||
pass
|
||||
return result
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
||||
@@ -99,7 +99,11 @@ class Array(use_metaclass(CachedMetaClass, pr.Base)):
|
||||
self._array = array
|
||||
|
||||
def get_index_types(self, indexes=[]):
|
||||
""" Get the types of a specific index or all, if not given """
|
||||
"""
|
||||
Get the types of a specific index or all, if not given.
|
||||
|
||||
:param indexes: The index input types.
|
||||
"""
|
||||
result = []
|
||||
if [index for index in indexes if isinstance(index, Slice)]:
|
||||
return [self]
|
||||
|
||||
Reference in New Issue
Block a user