Skip to content

Please consider making typing filter as good as comprehensions #11591

Closed
@NeilGirdhar

Description

@NeilGirdhar
from typing import Iterable, Optional
a: list[Optional[int]] = [1, None, 2]
b: Iterable[int] = filter(lambda x: x is not None, a)  # a.py:3: error: Argument 2 to "filter" has incompatible type "List[Optional[int]]"; expected "Iterable[int]"
c: Iterable[int] = (x
                    for x in a
                    if x is not None)  # Works great!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions