A backport of (copy and paste from) python 3.11’s StrEnum class for >=3.8.6:
See the design discussion,
and Ethan Furman’s first and
second PR with this implementation.
A slightly different implementation would likely be compatible with lower python versions;
PRs are welcome if they pass the test suite.
The existing (reference) implementation should still be the one used on supported versions.
Use with:
import sys
if sys.version_info >= (3, 11):
from enum import StrEnum
else:
from backports.strenum import StrEnum
class MyStrEnum(StrEnum):
POTATO = "potato"
ORANGE = "orange"
SPADE = "spade"
MyStrEnum.POTATO == "potato" # True
MyStrEnum.ORANGE.upper() == "ORANGE" # True
str(MyStrEnum.SPADE) == "spade" # True
|