-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
31f70d7
commit b6cb0ed
Showing
3 changed files
with
143 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters