Skip to content

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

Open

Description

@AndreyBalandin

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!

Activity

  1. ilevkivskyi commented on Aug 29, 2017

    @ilevkivskyi
    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.

  2. JelleZijlstra commented on Aug 29, 2017

    @JelleZijlstra
    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.

  3. ilevkivskyi commented on Aug 29, 2017

    @ilevkivskyi
    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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions