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