Merge pull request #1554 from PeterJCLaw/fix-nested-tuple-argument

Fix handling of nested tuple arguments
This commit is contained in:
Dave Halter
2020-05-08 12:49:44 +02:00
committed by GitHub
3 changed files with 59 additions and 2 deletions

View File

@@ -33,6 +33,7 @@ tpl_typed = ("2", 3) # type: Tuple[str, int]
collection = {"a": 1}
collection_typed = {"a": 1} # type: Dict[str, int]
list_of_ints = [42] # type: List[int]
list_of_funcs = [foo] # type: List[Callable[[T], T]]
custom_generic = CustomGeneric(123.45)
@@ -319,3 +320,21 @@ x7
for a in list_t_to_list_t(12):
#?
a
def list_tuple_t_to_tuple_list_t(the_list: List[Tuple[T]]) -> Tuple[List[T], ...]:
return tuple(list(x) for x in the_list)
for b in list_tuple_t_to_tuple_list_t(list_of_ints):
#?
b[0]
def list_tuple_t_elipsis_to_tuple_list_t(the_list: List[Tuple[T, ...]]) -> Tuple[List[T], ...]:
return tuple(list(x) for x in the_list)
for b in list_tuple_t_to_tuple_list_t(list_of_ints):
#?
b[0]

View File

@@ -80,6 +80,29 @@ for c2, in list_t_to_list_tuple_t(list_of_ints):
c2
# Test handling of nested tuple input parameters
def list_tuple_t_to_tuple_list_t(the_list: List[Tuple[T]]) -> Tuple[List[T], ...]:
return tuple(list(x) for x in the_list)
list_of_int_tuples = [(x,) for x in list_of_ints] # type: List[Tuple[int]]
for b in list_tuple_t_to_tuple_list_t(list_of_int_tuples):
#? int()
b[0]
def list_tuple_t_elipsis_to_tuple_list_t(the_list: List[Tuple[T, ...]]) -> Tuple[List[T], ...]:
return tuple(list(x) for x in the_list)
list_of_int_tuple_elipsis = [tuple(list_of_ints)] # type: List[Tuple[int, ...]]
for b in list_tuple_t_elipsis_to_tuple_list_t(list_of_int_tuple_elipsis):
#? int()
b[0]
# Test handling of nested callables
def foo(x: int) -> int:
return x