-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
as designedNot a bug, working as intendedNot a bug, working as intendedenhancement requestNew feature or requestNew feature or request
Description
Is your feature request related to a problem? Please describe.
Currently it seems that pyright does not support passing a type guard function as the first argument to the builtin filter function.
Here is an example:
# tmp.py
from typing import Iterable, Optional, TypeGuard
def is_not_none(x: Optional[int]) -> TypeGuard[int]:
return x is not None
generate_optional: Iterable[Optional[int]] = (x if x % 2 == 0 else None for x in range(100))
list_optional: list[Optional[int]] = [0, None, 1, None, 2]
generate_ints: Iterable[int] = filter(is_not_none, list_optional)$ pyright tmp.py
...
/home/jasha10/tmp.py:9:32 - error: Expression of type "filter[int | None]" cannot be assigned to declared type "Iterable[int]"
TypeVar "_T_co@Iterable" is covariant
Type "int | None" cannot be assigned to type "int"
Type "None" cannot be assigned to type "int" (reportGeneralTypeIssues)
1 error, 0 warnings, 0 infos
Describe the solution you'd like
It would be nice if type guard functions could be used with functional programming primitives such as filter.
Metadata
Metadata
Assignees
Labels
as designedNot a bug, working as intendedNot a bug, working as intendedenhancement requestNew feature or requestNew feature or request