forked from VimPlug/jedi
fix dictionary index problems
This commit is contained in:
@@ -815,26 +815,27 @@ class Array(use_metaclass(cache.CachedMetaClass, pr.Base)):
|
|||||||
return set(result)
|
return set(result)
|
||||||
|
|
||||||
def get_exact_index_types(self, mixed_index):
|
def get_exact_index_types(self, mixed_index):
|
||||||
""" Here the index is an int. Raises IndexError/KeyError """
|
""" Here the index is an int/str. Raises IndexError/KeyError """
|
||||||
index = mixed_index
|
index = mixed_index
|
||||||
if self.type == pr.Array.DICT:
|
if self.type == pr.Array.DICT:
|
||||||
index = None
|
index = None
|
||||||
for i, key_statement in enumerate(self._array.keys):
|
for i, key_statement in enumerate(self._array.keys):
|
||||||
# Because we only want the key to be a string.
|
# Because we only want the key to be a string.
|
||||||
key_elements = key_statement.get_commands()
|
key_commands = key_statement.get_commands()
|
||||||
if len(key_elements) == 1:
|
if len(key_commands) == 1:
|
||||||
|
key = key_commands[0]
|
||||||
|
key.get_code()
|
||||||
try:
|
try:
|
||||||
str_key = key_elements.get_code()
|
str_key = key.get_code()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
try:
|
str_key = None
|
||||||
str_key = key_elements[0].name
|
|
||||||
except AttributeError:
|
|
||||||
str_key = None
|
|
||||||
if mixed_index == str_key:
|
if mixed_index == str_key:
|
||||||
index = i
|
index = i
|
||||||
break
|
break
|
||||||
if index is None:
|
if index is None:
|
||||||
raise KeyError('No key found in dictionary')
|
raise KeyError('No key found in dictionary')
|
||||||
|
|
||||||
|
# Can raise an IndexError
|
||||||
values = [self._array.values[index]]
|
values = [self._array.values[index]]
|
||||||
return self._follow_values(values)
|
return self._follow_values(values)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user