Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please consider making typing filter as good as comprehensions #11591

Closed
NeilGirdhar opened this issue Nov 22, 2021 · 3 comments
Closed

Please consider making typing filter as good as comprehensions #11591

NeilGirdhar opened this issue Nov 22, 2021 · 3 comments
Labels
bug mypy got something wrong

Comments

@NeilGirdhar
Copy link
Contributor

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!
@NeilGirdhar NeilGirdhar added the bug mypy got something wrong label Nov 22, 2021
@NeilGirdhar NeilGirdhar changed the title Consider making typing filter as good as comprehensions Please consider making typing filter as good as comprehensions Nov 22, 2021
@sobolevn
Copy link
Member

sobolevn commented Nov 22, 2021

This would be solved after python/typeshed#6140 is merged! 👍

I've just checked it locally.

@NeilGirdhar
Copy link
Contributor Author

Awesome, thanks for checking!

@AlexWaygood
Copy link
Member

The relevant overload has been added to typeshed; see my remarks here for details on usage: #6847 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants