Skip to content

error: 'Union[Any, Tuple[Any, Any]]' object is not iterable #1855

Closed
@gvanrossum

Description

@gvanrossum

Code:

from typing import *
Pair = Tuple[Any, Any]
def f(a: Union[Any, Pair]):
    x, y = a  # E: 'Union[Any, Tuple[Any, Any]]' object is not iterable

If the type of argument is either just Any or just Pair the code passes. But with the union it gives the error.

UPDATE: I don't think the unreduced union is at fault -- an example with two different Tuple types of length 2 also fails. It's more that the unpack operation isn't tried for each variant of the union.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions