21 Oct
2020
21 Oct
'20
8:35 a.m.
Thank you for working on this PEP. I would like to ask, would `TypeGuard` be usable with `filter` (and perhaps `itertools.filterfalse`) as the PEP currently stands - would modifying the signature of `filter` in the typeshed be required and would it suffice - or would this behaviour need to be defined, if desired? For example: def is_two_element_tuple(val: Tuple[_T, ...]) -> TypeGuard[Tuple[_T, _T]]: return len(val) == 2 tuple_list = [(1, 2, 3), (4, 5)] reveal_type(tuple_list) # List[Tuple[int, ...]] two_tuple_list = list(filter(is_two_element_tuple, tuple_list)) # [(4, 5)] reveal_type(two_tuple_list) # List[Tuple[int, int]]