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

calling items() on Union of Dicts variable claims the return value is not iterable #3240

Closed
tjltjl opened this issue Apr 25, 2017 · 1 comment · Fixed by #4067
Closed

calling items() on Union of Dicts variable claims the return value is not iterable #3240

tjltjl opened this issue Apr 25, 2017 · 1 comment · Fixed by #4067
Assignees
Labels

Comments

@tjltjl
Copy link

tjltjl commented Apr 25, 2017

The code

    x : Union[Dict[int, int], Dict[str, str]] = dict(a='b')
    for a, b in x.items():
        print(a, b)

yields

error: 'Union[Tuple[builtins.int*, builtins.int*], Tuple[builtins.str*, builtins.str*]]' object is not iterable

Using just Dict[str, str] instead of the Union passes.

The code (naturally) runs in python, and both elements in the union are iterable...

@ilevkivskyi
Copy link
Member

I just checked, it looks like this is another multi-assign from Union problem.
@elazarg I think this is an important feature, and it would be great if you will continue working on your PR.

@ilevkivskyi ilevkivskyi self-assigned this Oct 6, 2017
JukkaL pushed a commit that referenced this issue Oct 11, 2017
Fixes #3859
Fixes #3240
Fixes #1855
Fixes #1575

This is a simple fix of various bugs and a crash based on the idea
originally proposed in #2219. The idea is to check assignment for 
every item in a union. However, in contrast to #2219, I think it will 
be more expected/consistent to construct a union of the resulting 
types instead of a join, for example:

```
x: Union[int, str]
x1 = x
reveal_type(x1) # Revealed type is 'Union[int, str]'

y: Union[Tuple[int], Tuple[str]]
(y1,) = y
reveal_type(y1) # Revealed type is 'Union[int, str]'
```

@elazarg did the initial work on this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants