From e455709a31b32d4927ed4436f4f19a272db6bcbb Mon Sep 17 00:00:00 2001 From: Peter Law Date: Sat, 22 Feb 2020 22:30:22 +0000 Subject: [PATCH] Add test case for nested generic callables --- test/completion/pep0484_generic_parameters.py | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/test/completion/pep0484_generic_parameters.py b/test/completion/pep0484_generic_parameters.py index f13fafd1..98522b7a 100644 --- a/test/completion/pep0484_generic_parameters.py +++ b/test/completion/pep0484_generic_parameters.py @@ -1,5 +1,14 @@ # python >= 3.4 -from typing import Iterable, List, Type, TypeVar, Dict, Mapping, Generic +from typing import ( + Callable, + Dict, + Generic, + Iterable, + List, + Mapping, + Type, + TypeVar, +) K = TypeVar('K') T = TypeVar('T') @@ -39,6 +48,25 @@ for b in list_type_t_to_list_t(list_of_int_type): b +def foo(x: T) -> T: + return x + + +list_of_funcs = [foo] # type: List[Callable[[T], T]] + +def list_func_t_to_list_func_type_t(the_list: List[Callable[[T], T]]) -> List[Callable[[Type[T]], T]]: + def adapt(func: Callable[[T], T]) -> Callable[[Type[T]], T]: + def wrapper(typ: Type[T]) -> T: + return func(typ()) + return wrapper + return [adapt(x) for x in the_list] + + +for b in list_func_t_to_list_func_type_t(list_of_funcs): + #? int() + b(int) + + mapping_int_str = {42: 'a'} # type: Dict[int, str] # Test that mappings (that have more than one parameter) are handled