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
{{ message }}
Repository navigation
iter doesn't work on TypeVar with bound of Enum #12553
A function that takes an argument of Type[_E] where _E = TypeVar("_E", bound=Enum) does not accept calling iter on that argument. Calling iter on a concrete enum class is accepted, which is why I think this isn't purely a typeshed issue. Using the class in a loop or calling the __iter__ member is also accepted.
I think this is a repro that doesn't involve enums, revealing that the issue is a general one with mypy's understanding of metaclasses rather than an issue specific to the enum plugin:
I guess a good question is whether subclasses of Foo are expected to have a metaclass that is a subclass (in the Liskov substitution sense) of Meta. If not, then the error would be legitimate since cls could be an instance of a subclass of Foo whose metaclass doesn't provide __iter__.
Activity
AlexWaygood commentedon Apr 9, 2022
I think this is a repro that doesn't involve enums, revealing that the issue is a general one with mypy's understanding of metaclasses rather than an issue specific to the enum plugin:
Mypy output:
AlexWaygood commentedon Apr 10, 2022
It probably doesn't even have anything to do with
TypeVars. I can reproduce a similar error with this snippet:bmerry commentedon Apr 11, 2022
I guess a good question is whether subclasses of Foo are expected to have a metaclass that is a subclass (in the Liskov substitution sense) of Meta. If not, then the error would be legitimate since
clscould be an instance of a subclass of Foo whose metaclass doesn't provide__iter__.Support protocol inference for Type[T] via metaclass (#14554)