Better usage of Enum if typing.Self is availiable

Using Self will not report an override / incompatible error.
This commit is contained in:
Daniel 2024-07-29 15:19:38 +02:00 committed by Daraan
parent 116cb5ccb1
commit 00b0efbfdb
1 changed files with 10 additions and 5 deletions

View File

@ -1,14 +1,19 @@
from enum import Enum
import sys
from typing import Callable, Iterable, Iterator, Union, Optional, overload, ClassVar, Any, Literal
if sys.version_info < (3, 11):
from typing_extensions import Self
else:
from typing import Self
class __CarlaEnum(Enum):
"""
CARLA's Enums have a `values` entry that is not part of the python enum.Enum class.
This abstract class adds this method.
CARLA's Enums have a `values` and `names` attribute that are not part of the python `enum.Enum`
class. This abstract stub class adds these attributes.
"""
values : ClassVar[dict[int, "__CarlaEnum"]]
names : ClassVar[dict[str, "__CarlaEnum"]]
values : ClassVar[dict[int, Self]]
names : ClassVar[dict[str, Self]]
def __init_subclass__(cls):
cls.values : dict[int, cls]