Calling iter()
on a string enum
#1464
Replies: 1 comment 2 replies
-
Starting with Python 3.12 you should be able to make this work with a simple
As the comment below pointed out the code is fine, it looks like that specific check not working is a mypy bug, if instead of creating an e.g. |
Beta Was this translation helpful? Give feedback.
-
Hi, consider the following code:
which creates a "string enum". Members and strings can be used exchangeably. Now, you can check for membership with the following code:
This works without problems, but mypy complains because the type of
iter(Foo)
isIterator[Foo]
instead of something likeIterator[Union[Foo, str]]
. Is this possible with mypy? I do not want to add too much complexity to the enum, if possible. It looks like a mypy bug to me that the iterator type is not compatible withstr
.Beta Was this translation helpful? Give feedback.
All reactions