Skip to content

Commit

Permalink
copy workaround from ahbicht
Browse files Browse the repository at this point in the history
  • Loading branch information
hf-kklein committed Mar 27, 2024
1 parent 8a98177 commit 0e43445
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/edi_energy_scraper/epoch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,25 @@
this module contains the epoch enum
"""

from enum import StrEnum
import sys

if sys.version_info.major == 3 and sys.version_info.minor >= 11:
from enum import StrEnum

# We have to use the builtin / std lib enum.StrEnum in Python >= 3.11, because the behaviour of (str,Enum) changed:
# class Foo(str, Enum):
# MEMBER = "MEMBER"
# f"{a_str_enum_member}" results in "MEMBER" for Python < v3.11 but "Foo.MEMBER" in Python >= v3.11
else:
from enum import Enum

class StrEnum(str, Enum): # type:ignore[no-redef]
"""
An enum class of which each member has a string representation.
This is a workaround for Python <v3.11 because enum.StrEnum was introduced in Python 3.11.
"""

# We'll live with this class for Python <v3.11. The unit test for python 3.9-3.11 ensure that this works.


class Epoch(StrEnum): # pylint: disable=too-few-public-methods
Expand Down

0 comments on commit 0e43445

Please sign in to comment.