You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow iterable class objects to be unpacked (including enums) (#14827)
Fixes#14782
Currently, mypy issues a false positive if you try to unpack an enum
class:
```python
from enum import Enum
class E(Enum):
A = 1
B = 2
A, B = E # error: "Type[E]" object is not iterable [misc]
```
This is because of a more general problem with class objects that have
`__iter__` defined on their metaclass. Mypy issues a false positive on
this code, where `Foo` is iterable by virtue of having `Meta` as its
metaclass:
```python
from typing import Iterator
class Meta(type):
def __iter__(cls) -> Iterator[int]:
yield from [1, 2, 3]
class Foo(metaclass=Meta): ...
a, b, c = Foo # error: "Type[Foo]" object is not iterable [misc]
reveal_type(a) # error: Cannot determine type of "a" [has-type] # note: Revealed type is "Any"
```
This PR fixes the false positive with enums, and the more general false
positive with iterable class objects.
0 commit comments