Skip to content

Type inference regression involving filter(None, ...) #8093

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

Closed
JukkaL opened this issue Dec 5, 2019 · 0 comments · Fixed by #8095
Closed

Type inference regression involving filter(None, ...) #8093

JukkaL opened this issue Dec 5, 2019 · 0 comments · Fixed by #8095
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-0-high

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Dec 5, 2019

This example started generating errors after #8077:

from typing import Optional, TypeVar, Iterable, Iterator, List

_T = TypeVar('_T')

def filter(__function: None, __iterable: Iterable[Optional[_T]]) -> List[_T]: ...

x: Optional[str]

# Need type annotation for 'pagelets'
# List item 0 has incompatible type "Optional[str]"; expected "None"
pagelets = filter(None, [x])

The issue also happens with Python 2 filter(), at least.

cc @ilevkivskyi

@JukkaL JukkaL added bug mypy got something wrong priority-0-high false-positive mypy gave an error on correct code labels Dec 5, 2019
ilevkivskyi added a commit that referenced this issue Dec 5, 2019
Fixes #8093

The fix is kind of simple, we really need to keep all `ErasedType`s intact to preserve the existing type inference logic, but it is also long because I need to thread the flag down like dozen function calls.

The issue itself btw highlight how fragile is current type inference logic (note that `expand_type()` implicitly calls `make_simplified_union()` too, but I think that one doesn't need to be updated because it shouldn't be called with any erased components).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-0-high
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant