I have a function that prints names of the all possible options in the enumeration.
When I run the mypy
for my code it gives: error: Need type annotation for 'item' [var-annotated]
Here is my code:
import enum
def function(enumeration: enum.EnumMeta) -> None:
options = (item.name for item in enumeration)
print(f"Valid options are: {', '.join(options)}")
I don't want to ignore it or use the normal for loop. Is there any way to annotate it?
EDIT:
I have already tried the below methods:
item: TypeOfItem
options = (item.name for item in enumeration)
and
from typing import cast
options = (cast(TypeOfItem, item).name for item in enumeration)