forked from VimPlug/jedi
Support passing through values for non-annotated tuples
This commit is contained in:
@@ -329,6 +329,11 @@ class SequenceLiteralValue(Sequence):
|
|||||||
self.array_type = SequenceLiteralValue.mapping[atom.children[0]]
|
self.array_type = SequenceLiteralValue.mapping[atom.children[0]]
|
||||||
"""The builtin name of the array (list, set, tuple or dict)."""
|
"""The builtin name of the array (list, set, tuple or dict)."""
|
||||||
|
|
||||||
|
def _get_generics(self):
|
||||||
|
if self.array_type == u'tuple':
|
||||||
|
return tuple(x.infer().py__class__() for x in self.py__iter__())
|
||||||
|
return super(SequenceLiteralValue, self)._get_generics()
|
||||||
|
|
||||||
def py__simple_getitem__(self, index):
|
def py__simple_getitem__(self, index):
|
||||||
"""Here the index is an int/str. Raises IndexError/KeyError."""
|
"""Here the index is an int/str. Raises IndexError/KeyError."""
|
||||||
if isinstance(index, slice):
|
if isinstance(index, slice):
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
from typing import Any, Iterable, List, Tuple, TypeVar
|
from typing import Any, Iterable, List, Tuple, TypeVar
|
||||||
|
|
||||||
T = TypeVar('T')
|
T = TypeVar('T')
|
||||||
|
U = TypeVar('U')
|
||||||
TList = TypeVar('TList', bound=List[Any])
|
TList = TypeVar('TList', bound=List[Any])
|
||||||
|
|
||||||
untyped_list_str = ['abc', 'def']
|
untyped_list_str = ['abc', 'def']
|
||||||
@@ -10,6 +11,9 @@ typed_list_str = ['abc', 'def'] # type: List[str]
|
|||||||
untyped_tuple_str = ('abc',)
|
untyped_tuple_str = ('abc',)
|
||||||
typed_tuple_str = ('abc',) # type: Tuple[str]
|
typed_tuple_str = ('abc',) # type: Tuple[str]
|
||||||
|
|
||||||
|
untyped_tuple_str_int = ('abc', 4)
|
||||||
|
typed_tuple_str_int = ('abc', 4) # type: Tuple[str, int]
|
||||||
|
|
||||||
|
|
||||||
def untyped_passthrough(x):
|
def untyped_passthrough(x):
|
||||||
return x
|
return x
|
||||||
@@ -20,6 +24,9 @@ def typed_list_generic_passthrough(x: List[T]) -> List[T]:
|
|||||||
def typed_tuple_generic_passthrough(x: Tuple[T]) -> Tuple[T]:
|
def typed_tuple_generic_passthrough(x: Tuple[T]) -> Tuple[T]:
|
||||||
return x
|
return x
|
||||||
|
|
||||||
|
def typed_multi_typed_tuple_generic_passthrough(x: Tuple[T, U]) -> Tuple[U, T]:
|
||||||
|
return x[1], x[0]
|
||||||
|
|
||||||
def typed_iterable_generic_passthrough(x: Iterable[T]) -> Iterable[T]:
|
def typed_iterable_generic_passthrough(x: Iterable[T]) -> Iterable[T]:
|
||||||
return x
|
return x
|
||||||
|
|
||||||
@@ -66,6 +73,20 @@ for h in typed_tuple_generic_passthrough(typed_tuple_str):
|
|||||||
h
|
h
|
||||||
|
|
||||||
|
|
||||||
|
out_untyped = typed_multi_typed_tuple_generic_passthrough(untyped_tuple_str_int)
|
||||||
|
#? int()
|
||||||
|
out_untyped[0]
|
||||||
|
#? str()
|
||||||
|
out_untyped[1]
|
||||||
|
|
||||||
|
|
||||||
|
out_typed = typed_multi_typed_tuple_generic_passthrough(typed_tuple_str_int)
|
||||||
|
#? int()
|
||||||
|
out_typed[0]
|
||||||
|
#? str()
|
||||||
|
out_typed[1]
|
||||||
|
|
||||||
|
|
||||||
for n in typed_fully_generic_passthrough(untyped_list_str):
|
for n in typed_fully_generic_passthrough(untyped_list_str):
|
||||||
#? str()
|
#? str()
|
||||||
n
|
n
|
||||||
|
|||||||
Reference in New Issue
Block a user