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
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.
To Reproduce
Actual Behavior
This code generates an error:
Expected Behavior
This should type check without errors. Note that mypy knows that
E
is actually iterable. For example,works fine and so does iterating over
E
in a for loop.Your Environment
mypy 1.1.0+dev.c23e831ab0e7ec827c38cc830d3ebd3f4c43cd75
--strict
The text was updated successfully, but these errors were encountered: