Closed
Description
Bug report
In python < 3.9
, creating a subclass of both enum.Enum
and typing.Generic
(or a subclass of typing.Generic
) causes an error.
from enum import Enum
from typing import Generic, TypeVar
T = TypeVar("T")
class Foo(Generic[T]):
...
class Bar(Foo[int], Enum):
x = 0
Error:
Traceback (most recent call last):
File "test.py", line 11, in <module>
class Bar(Foo[int], Enum):
File "...\enum_newest.py", line 566, in __new__
raise exc
File "...\enum_newest.py", line 275, in __set_name__
enum_member = enum_class._new_member_(enum_class, *args)
File "...\Python38\lib\typing.py", line 875, in __new__
obj = super().__new__(cls, *args, **kwds)
File "...\enum_newest.py", line 1132, in __new__
raise ve_exc
ValueError: 0 is not a valid Bar
Trying this with newer versions of enum.py
does not appear to solve the issue, meaning it probably has something to do with a change in typing.Generic
in python = 3.9
that happened to fix it. I wasn't able to test newer versions of typing.py
since it was pretty complicated and used imports not available in previous versions.
I also couldn't find anything about such a change to typing.Generic
, and I'm not sure if this is a more general issue concerning how enum.Enum
plays with special situations considering the current enum.py
still gives the above error.