From b8987fe4512415b9f54fd93d55b7151aab693c02 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Thu, 3 Apr 2014 19:05:29 +0200 Subject: [PATCH] CompiledObject.get_index_types implementation example --- jedi/evaluate/compiled/__init__.py | 10 ++++++++++ test/test_api/test_interpreter.py | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/jedi/evaluate/compiled/__init__.py b/jedi/evaluate/compiled/__init__.py index 8cd6a5e7..109c1b30 100644 --- a/jedi/evaluate/compiled/__init__.py +++ b/jedi/evaluate/compiled/__init__.py @@ -93,6 +93,16 @@ class CompiledObject(Base): else: 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 def name(self): # might not exist sometimes (raises AttributeError) diff --git a/test/test_api/test_interpreter.py b/test/test_api/test_interpreter.py index 10c344ed..d7b7a0fd 100644 --- a/test/test_api/test_interpreter.py +++ b/test/test_api/test_interpreter.py @@ -44,7 +44,10 @@ class TestInterpreterAPI(TestCase): completions) def test_list(self): - array = ['haha'] + array = ['haha', 1] self.check_interpreter_complete('array[0].uppe', locals(), ['upper']) + self.check_interpreter_complete('array[0].real', + locals(), + [])