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

mypy is confused by ItemsView unpacking #11685

Closed
ZeeD opened this issue Dec 8, 2021 · 4 comments
Closed

mypy is confused by ItemsView unpacking #11685

ZeeD opened this issue Dec 8, 2021 · 4 comments
Labels
bug mypy got something wrong

Comments

@ZeeD
Copy link

ZeeD commented Dec 8, 2021

Bug Report

It seems to me that mypy doesn't known that ItemsView can be "unpacked" as an iterable of pairs

To Reproduce

issue.py:

items = ({'a': 'x', 'b': 'y', 'c': 'z'}).items()
items2 = (*items, )
items3 = (*iter(items), )

reveal_locals()

k, v = next(iter(items))
k2, v2 = next(iter(items2))
k3, v3 = next(iter(items3))
>mypy issue.py
issue.py:5: note: Revealed local types are:
issue.py:5: note:     items: typing.ItemsView[builtins.str*, builtins.str*]
issue.py:5: note:     items2: builtins.tuple[builtins.str*]
issue.py:5: note:     items3: builtins.tuple[Tuple[builtins.str*, builtins.str*]]
issue.py:8: error: Unpacking a string is disallowed
Found 1 error in 1 file (checked 1 source file)

>mypy --version
mypy 0.910

Expected Behavior

no errors: items2 should have the same "type" of items3 - as there is no errors running the snippet of code in python

@ZeeD ZeeD added the bug mypy got something wrong label Dec 8, 2021
@sobolevn
Copy link
Member

sobolevn commented Dec 8, 2021

Works for me on master:

» mypy out/ex.py --strict-optional --warn-unreachable --show-traceback
out/ex.py:5: note: Revealed local types are:
out/ex.py:5: note:     items: _collections_abc.dict_items[builtins.str*, builtins.str*]
out/ex.py:5: note:     items2: builtins.tuple[Tuple[builtins.str*, builtins.str*]]
out/ex.py:5: note:     items3: builtins.tuple[Tuple[builtins.str*, builtins.str*]]

@ZeeD
Copy link
Author

ZeeD commented Dec 8, 2021

oh, cool!
do you have an idea on when current master will be released?

@JelleZijlstra
Copy link
Member

JelleZijlstra commented Dec 8, 2021

You can follow along in #11158. There's a lot on master now that's not going to be in 0.920, though. I don't know whether that includes the fix for this bug.

@JelleZijlstra
Copy link
Member

We did finally release the fix for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants