mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Fix: __getitem__ sometimes didnt evaluate all the types.
This commit is contained in:
@@ -519,10 +519,10 @@ def py__getitem__(evaluator, types, index, node):
|
|||||||
try:
|
try:
|
||||||
result |= getitem(index)
|
result |= getitem(index)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return py__iter__types(evaluator, set([typ]))
|
result |= py__iter__types(evaluator, set([typ]))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# Must be a dict. Lists don't raise IndexErrors.
|
# Must be a dict. Lists don't raise IndexErrors.
|
||||||
return typ.values()
|
result |= typ.values()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -198,21 +198,15 @@ class Instance(use_metaclass(CachedMetaClass, Executed)):
|
|||||||
for names_dict in self.base.names_dicts(search_global=False, is_instance=True):
|
for names_dict in self.base.names_dicts(search_global=False, is_instance=True):
|
||||||
yield LazyInstanceDict(self._evaluator, self, names_dict)
|
yield LazyInstanceDict(self._evaluator, self, names_dict)
|
||||||
|
|
||||||
def get_index_types(self, evaluator, index_array):
|
def py__getitem__(self, index):
|
||||||
indexes = iterable.create_indexes_or_slices(self._evaluator, index_array)
|
|
||||||
if any([isinstance(i, iterable.Slice) for i in indexes]):
|
|
||||||
# Slice support in Jedi is very marginal, at the moment, so just
|
|
||||||
# ignore them in case of __getitem__.
|
|
||||||
# TODO support slices in a more general way.
|
|
||||||
indexes = []
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
method = self.get_subscope_by_name('__getitem__')
|
method = self.get_subscope_by_name('__getitem__')
|
||||||
except KeyError:
|
except KeyError:
|
||||||
debug.warning('No __getitem__, cannot access the array.')
|
debug.warning('No __getitem__, cannot access the array.')
|
||||||
return set()
|
return set()
|
||||||
else:
|
else:
|
||||||
return self._evaluator.execute(method, [iterable.AlreadyEvaluated(indexes)])
|
index_obj = compiled.create(self._evaluator, index)
|
||||||
|
return self._evaluator.execute_evaluated(method, index_obj)
|
||||||
|
|
||||||
def py__iter__(self):
|
def py__iter__(self):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -41,11 +41,11 @@ b[int():]
|
|||||||
|
|
||||||
|
|
||||||
class _StrangeSlice():
|
class _StrangeSlice():
|
||||||
def __getitem__(self, slice):
|
def __getitem__(self, sliced):
|
||||||
return slice
|
return sliced
|
||||||
|
|
||||||
# Should not result in an error, just because the slice itself is returned.
|
# Should not result in an error, just because the slice itself is returned.
|
||||||
#? []
|
#? slice()
|
||||||
_StrangeSlice()[1:2]
|
_StrangeSlice()[1:2]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user