mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +08:00
CompiledObject.get_index_types implementation example
This commit is contained in:
@@ -93,6 +93,16 @@ 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):
|
||||||
|
# If the object doesn't have `__getitem__`, just raise the
|
||||||
|
# AttributeError.
|
||||||
|
self.obj.__getitem__
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.obj[mixed_obj]
|
||||||
|
except (KeyError, IndexError):
|
||||||
|
raise AttributeError()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
# might not exist sometimes (raises AttributeError)
|
# might not exist sometimes (raises AttributeError)
|
||||||
|
|||||||
@@ -44,7 +44,10 @@ class TestInterpreterAPI(TestCase):
|
|||||||
completions)
|
completions)
|
||||||
|
|
||||||
def test_list(self):
|
def test_list(self):
|
||||||
array = ['haha']
|
array = ['haha', 1]
|
||||||
self.check_interpreter_complete('array[0].uppe',
|
self.check_interpreter_complete('array[0].uppe',
|
||||||
locals(),
|
locals(),
|
||||||
['upper'])
|
['upper'])
|
||||||
|
self.check_interpreter_complete('array[0].real',
|
||||||
|
locals(),
|
||||||
|
[])
|
||||||
|
|||||||
Reference in New Issue
Block a user