-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Error on dict construction from iterable items #9938
Comments
Hi @jaraco, I think that's a reasonable error -- mypy doesn't keep track of the length of the sequence returned by I guess you could rewrite this as follows to help mypy along:
Or if you want
or
|
Hey Guido. Thanks for the quick response. The real-world use-case is in how The error emerged in pypa/twine#728 when attempting to demonstrate this more concise approach when switching from pkg_resources. I think if I'd known this approach was effectively invalid, I'd probably have come up with a different design for querying entry points, something that involved custom containers that could give consumers a clean API with one import. Given that the type system can't effectively honor this use-case, would you recommend to avoid the use case or to ignore it for mypy checks? |
Bug Report
Attempting to construct a mapping from objects that are designed to be constructed into dict items results in an error.
To Reproduce
Run mypy on this file:
In this file, MyObject implements
__iter__
to return a key/value pair such that a dict can be constructed from an iterable of MyObjects.Note that
python -m doctest dictable.py
passes.Expected Behavior
Mypy should honor
dict
's behavior to produce pairs from objects if they're iterable and accept any iterable of objects that when iterated on produce pairs of compatible types.Actual Behavior
Your Environment
mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: