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

dict(zip()) and itertools.product #3884

Open
AndreyBalandin opened this issue Aug 29, 2017 · 3 comments
Open

dict(zip()) and itertools.product #3884

AndreyBalandin opened this issue Aug 29, 2017 · 3 comments
Labels
feature priority-2-low topic-plugins The plugin API and ideas for new plugins

Comments

@AndreyBalandin
Copy link

AndreyBalandin commented Aug 29, 2017

I think I've noticed a tiny bug.
Python 3.6.1
mypy 0.521

from typing import Tuple, Dict
from itertools import product

# works fine
XY_1: Dict[str, Tuple[int, int]] = dict(zip('abcd', product(range(2), range(2))))
# {'a': (0, 0), 'b': (0, 1), 'c': (1, 0), 'd': (1, 1)}

# error for this one
XY_2: Dict[str, Tuple[int, int]] = dict(zip('abcd', product(range(2), repeat=2)))
# {'a': (0, 0), 'b': (0, 1), 'c': (1, 0), 'd': (1, 1)}

The dictionaries are the same.
Error output:

mypy_test.py:10: error: Argument 2 to "zip" has incompatible type Iterator[Tuple[int]]; expected Iterable[Tuple[int, int]]

I think that this is not essential. So, just in case.
Thanks for the great product!

@ilevkivskyi
Copy link
Member

This is an example of #3541, we currently only support literals via the plugins (no special support for dependent types yet). I will reference this issue there as an example.

@JelleZijlstra
Copy link
Member

Even if we could be more precise with a plugin here, I think there's a bug in the typeshed stubs for product (introduced perhaps by @matthiaskramm's python/typeshed#1393): the repeat argument is ignored.

@ilevkivskyi
Copy link
Member

@JelleZijlstra Yes, I think there should be something like several overloads without repeat, and then one with repeat that returns Iterable[Tuple[T, ...]]. Maybe we should open a separate issue at typeshed tracker, and only track the plugin here, what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature priority-2-low topic-plugins The plugin API and ideas for new plugins
Projects
None yet
Development

No branches or pull requests

3 participants