mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-18 19:45:57 +08:00
Get completely rid of get_index_types.
This commit is contained in:
@@ -168,38 +168,6 @@ 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, evaluator, index_array=()):
|
|
||||||
# If the object doesn't have `__getitem__`, just raise the
|
|
||||||
# AttributeError.
|
|
||||||
raise NotImplementedError
|
|
||||||
if not hasattr(self.obj, '__getitem__'):
|
|
||||||
debug.warning('Tried to call __getitem__ on non-iterable.')
|
|
||||||
return set()
|
|
||||||
if type(self.obj) not in (str, list, tuple, unicode, bytes, bytearray, dict):
|
|
||||||
# Get rid of side effects, we won't call custom `__getitem__`s.
|
|
||||||
return set()
|
|
||||||
|
|
||||||
result = set()
|
|
||||||
from jedi.evaluate.iterable import create_indexes_or_slices
|
|
||||||
for typ in create_indexes_or_slices(evaluator, index_array):
|
|
||||||
index = None
|
|
||||||
try:
|
|
||||||
index = typ.obj
|
|
||||||
new = self.obj[index]
|
|
||||||
except (KeyError, IndexError, TypeError, AttributeError):
|
|
||||||
# Just try, we don't care if it fails, except for slices.
|
|
||||||
if isinstance(index, slice):
|
|
||||||
result.add(self)
|
|
||||||
else:
|
|
||||||
result.add(CompiledObject(new))
|
|
||||||
if not result:
|
|
||||||
try:
|
|
||||||
for obj in self.obj:
|
|
||||||
result.add(CompiledObject(obj))
|
|
||||||
except TypeError:
|
|
||||||
pass # self.obj maynot have an __iter__ method.
|
|
||||||
return result
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def py__getitem__(self):
|
def py__getitem__(self):
|
||||||
if not hasattr(self.obj, '__getitem__'):
|
if not hasattr(self.obj, '__getitem__'):
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ It is important to note that:
|
|||||||
1. Array modfications work only in the current module.
|
1. Array modfications work only in the current module.
|
||||||
2. Jedi only checks Array additions; ``list.pop``, etc are ignored.
|
2. Jedi only checks Array additions; ``list.pop``, etc are ignored.
|
||||||
"""
|
"""
|
||||||
from jedi.common import unite, ignored, safe_property
|
from jedi.common import unite, safe_property
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi import settings
|
from jedi import settings
|
||||||
from jedi._compatibility import use_metaclass, unicode, zip_longest
|
from jedi._compatibility import use_metaclass, unicode, zip_longest
|
||||||
@@ -54,9 +54,6 @@ class GeneratorMixin(object):
|
|||||||
def py__bool__(self):
|
def py__bool__(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def get_index_types(self):
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def py__class__(self, evaluator):
|
def py__class__(self, evaluator):
|
||||||
gen_obj = compiled.get_special_object(self._evaluator, 'GENERATOR_OBJECT')
|
gen_obj = compiled.get_special_object(self._evaluator, 'GENERATOR_OBJECT')
|
||||||
return gen_obj.py__class__(evaluator)
|
return gen_obj.py__class__(evaluator)
|
||||||
@@ -193,9 +190,6 @@ class ArrayMixin(object):
|
|||||||
class ListComprehension(Comprehension, ArrayMixin):
|
class ListComprehension(Comprehension, ArrayMixin):
|
||||||
type = 'list'
|
type = 'list'
|
||||||
|
|
||||||
def get_index_types(self, evaluator, index):
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def py__getitem__(self, index):
|
def py__getitem__(self, index):
|
||||||
all_types = list(self.py__iter__())
|
all_types = list(self.py__iter__())
|
||||||
return all_types[index]
|
return all_types[index]
|
||||||
@@ -231,31 +225,6 @@ class Array(IterableWrapper, ArrayMixin):
|
|||||||
def name(self):
|
def name(self):
|
||||||
return helpers.FakeName(self.type, parent=self)
|
return helpers.FakeName(self.type, parent=self)
|
||||||
|
|
||||||
@memoize_default()
|
|
||||||
def get_index_types(self, evaluator, index=()):
|
|
||||||
"""
|
|
||||||
Get the types of a specific index or all, if not given.
|
|
||||||
|
|
||||||
:param index: A subscriptlist node (or subnode).
|
|
||||||
"""
|
|
||||||
raise NotImplementedError
|
|
||||||
indexes = create_index_types(evaluator, index)
|
|
||||||
lookup_done = False
|
|
||||||
types = set()
|
|
||||||
for index in indexes:
|
|
||||||
if isinstance(index, Slice):
|
|
||||||
types.add(self)
|
|
||||||
lookup_done = True
|
|
||||||
elif isinstance(index, compiled.CompiledObject) \
|
|
||||||
and isinstance(index.obj, (int, str, unicode)):
|
|
||||||
with ignored(KeyError, IndexError, TypeError):
|
|
||||||
# TODO REMOVE the ignores. this should not be the case,
|
|
||||||
# because it tends to swallow errors.
|
|
||||||
types |= self.get_exact_index_types(index.obj)
|
|
||||||
lookup_done = True
|
|
||||||
|
|
||||||
return types if lookup_done else self.values()
|
|
||||||
|
|
||||||
@memoize_default()
|
@memoize_default()
|
||||||
def values(self):
|
def values(self):
|
||||||
result = unite(self._evaluator.eval_element(v) for v in self._values())
|
result = unite(self._evaluator.eval_element(v) for v in self._values())
|
||||||
@@ -296,6 +265,7 @@ class Array(IterableWrapper, ArrayMixin):
|
|||||||
raise AttributeError('Strange access on %s: %s.' % (self, name))
|
raise AttributeError('Strange access on %s: %s.' % (self, name))
|
||||||
return getattr(self.atom, name)
|
return getattr(self.atom, name)
|
||||||
|
|
||||||
|
# @memoize_default()
|
||||||
def py__iter__(self):
|
def py__iter__(self):
|
||||||
"""
|
"""
|
||||||
While values returns the possible values for any array field, this
|
While values returns the possible values for any array field, this
|
||||||
|
|||||||
Reference in New Issue
Block a user