forked from VimPlug/jedi
Remove get_index_and_execute and use something else
This commit is contained in:
@@ -3,9 +3,10 @@ This module is about generics, like the `int` in `List[int]`. It's not about
|
|||||||
the Generic class.
|
the Generic class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from jedi import debug
|
||||||
from jedi.cache import memoize_method
|
from jedi.cache import memoize_method
|
||||||
from jedi.inference.utils import to_tuple
|
from jedi.inference.utils import to_tuple
|
||||||
from jedi.inference.base_value import ValueSet
|
from jedi.inference.base_value import ValueSet, NO_VALUES
|
||||||
from jedi.inference.value.iterable import SequenceLiteralValue
|
from jedi.inference.value.iterable import SequenceLiteralValue
|
||||||
from jedi.inference.helpers import is_string
|
from jedi.inference.helpers import is_string
|
||||||
|
|
||||||
@@ -22,7 +23,16 @@ def _resolve_forward_references(context, value_set):
|
|||||||
yield value
|
yield value
|
||||||
|
|
||||||
|
|
||||||
class LazyGenericManager(object):
|
class _AbstractGenericManager(object):
|
||||||
|
def get_index_and_execute(self, index):
|
||||||
|
try:
|
||||||
|
return self[index].execute_annotation()
|
||||||
|
except IndexError:
|
||||||
|
debug.warning('No param #%s found for annotation %s', index, self)
|
||||||
|
return NO_VALUES
|
||||||
|
|
||||||
|
|
||||||
|
class LazyGenericManager(_AbstractGenericManager):
|
||||||
def __init__(self, context_of_index, index_value):
|
def __init__(self, context_of_index, index_value):
|
||||||
self._context_of_index = context_of_index
|
self._context_of_index = context_of_index
|
||||||
self._index_value = index_value
|
self._index_value = index_value
|
||||||
@@ -65,7 +75,7 @@ class LazyGenericManager(object):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
class TupleGenericManager(object):
|
class TupleGenericManager(_AbstractGenericManager):
|
||||||
def __init__(self, tup):
|
def __init__(self, tup):
|
||||||
self._tuple = tup
|
self._tuple = tup
|
||||||
|
|
||||||
|
|||||||
@@ -219,22 +219,13 @@ class TypeAlias(LazyValueWrapper):
|
|||||||
return cls
|
return cls
|
||||||
|
|
||||||
|
|
||||||
class _GetItemMixin(object):
|
class Callable(_WithIndexBase):
|
||||||
def _get_getitem_values(self, index):
|
|
||||||
try:
|
|
||||||
return self._generics_manager[index]
|
|
||||||
except IndexError:
|
|
||||||
debug.warning('No param #%s found for annotation %s', index, self._generics_manager)
|
|
||||||
return NO_VALUES
|
|
||||||
|
|
||||||
|
|
||||||
class Callable(_WithIndexBase, _GetItemMixin):
|
|
||||||
def py__call__(self, arguments):
|
def py__call__(self, arguments):
|
||||||
# The 0th index are the arguments.
|
# The 0th index are the arguments.
|
||||||
return self._get_getitem_values(1).execute_annotation()
|
return self._generics_manager.get_index_and_execute(1)
|
||||||
|
|
||||||
|
|
||||||
class Tuple(LazyValueWrapper, _GetItemMixin):
|
class Tuple(LazyValueWrapper):
|
||||||
def __init__(self, inference_state, parent_context, name, generics_manager):
|
def __init__(self, inference_state, parent_context, name, generics_manager):
|
||||||
self.inference_state = inference_state
|
self.inference_state = inference_state
|
||||||
self.parent_context = parent_context
|
self.parent_context = parent_context
|
||||||
@@ -247,24 +238,24 @@ class Tuple(LazyValueWrapper, _GetItemMixin):
|
|||||||
|
|
||||||
def py__simple_getitem__(self, index):
|
def py__simple_getitem__(self, index):
|
||||||
if self._is_homogenous():
|
if self._is_homogenous():
|
||||||
return self._get_getitem_values(0).execute_annotation()
|
return self._generics_manager.get_index_and_execute(0)
|
||||||
else:
|
else:
|
||||||
if isinstance(index, int):
|
if isinstance(index, int):
|
||||||
return self._get_getitem_values(index).execute_annotation()
|
return self._generics_manager.get_index_and_execute(index)
|
||||||
|
|
||||||
debug.dbg('The getitem type on Tuple was %s' % index)
|
debug.dbg('The getitem type on Tuple was %s' % index)
|
||||||
return NO_VALUES
|
return NO_VALUES
|
||||||
|
|
||||||
def py__iter__(self, contextualized_node=None):
|
def py__iter__(self, contextualized_node=None):
|
||||||
if self._is_homogenous():
|
if self._is_homogenous():
|
||||||
yield LazyKnownValues(self._get_getitem_values(0).execute_annotation())
|
yield LazyKnownValues(self._generics_manager.get_index_and_execute(0))
|
||||||
else:
|
else:
|
||||||
for v in self._generics_manager.to_tuple():
|
for v in self._generics_manager.to_tuple():
|
||||||
yield LazyKnownValues(v.execute_annotation())
|
yield LazyKnownValues(v.execute_annotation())
|
||||||
|
|
||||||
def py__getitem__(self, index_value_set, contextualized_node):
|
def py__getitem__(self, index_value_set, contextualized_node):
|
||||||
if self._is_homogenous():
|
if self._is_homogenous():
|
||||||
return self._get_getitem_values(0).execute_annotation()
|
return self._generics_manager.get_index_and_execute(0)
|
||||||
|
|
||||||
return ValueSet.from_sets(
|
return ValueSet.from_sets(
|
||||||
self._generics_manager.to_tuple()
|
self._generics_manager.to_tuple()
|
||||||
@@ -276,11 +267,11 @@ class Tuple(LazyValueWrapper, _GetItemMixin):
|
|||||||
return tuple_
|
return tuple_
|
||||||
|
|
||||||
|
|
||||||
class Generic(_WithIndexBase, _GetItemMixin):
|
class Generic(_WithIndexBase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Protocol(_WithIndexBase, _GetItemMixin):
|
class Protocol(_WithIndexBase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user