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

[Bug] Using filter in itertools.chain makes them both infer wrong types. #8226

Open
Jackenmen opened this issue Jan 1, 2020 · 0 comments
Open
Labels
bug mypy got something wrong topic-inference When to infer types or require explicit annotations topic-join-v-union Using join vs. using unions

Comments

@Jackenmen
Copy link

Repro:

import itertools
from typing import List

x: List[int] = [1, 2, 3]
y: List[str] = ["  ", "", "abc"]


it = itertools.chain(x, filter(lambda s: s.strip() == "", y))
reveal_type(it)

Actual output:

main.py:8: error: "object" has no attribute "strip"
main.py:9: note: Revealed type is 'itertools.chain[builtins.object*]'

Expected output:
I was expecting no errors and didn't expect filter to be affected by what it is put in, i.e. if you put filter call separate from itertools.chain, it prevents the first errors about missing strip attr:

f = filter(lambda s: s.strip() == "", y)
it = itertools.chain(x, f)
reveal_type(it)

The revealed type is still wrong though.


Python version: 3.7.6
Mypy version: 0.760 (still occurs on master)
Used flags: --strict

@AlexWaygood AlexWaygood added bug mypy got something wrong topic-join-v-union Using join vs. using unions topic-inference When to infer types or require explicit annotations labels Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-inference When to infer types or require explicit annotations topic-join-v-union Using join vs. using unions
Projects
None yet
Development

No branches or pull requests

2 participants