Skip to content

Commit

Permalink
Use custom StrEnum
Browse files Browse the repository at this point in the history
  • Loading branch information
chanhosuh committed Oct 31, 2023
1 parent 17c828e commit c366426
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions curvesim/constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
"""
Constants and Enum types used in Curvesim.
"""
from enum import Enum


class Chain(str, Enum):
class StrEnum(str, Enum):
"""
Custom string enum type since the builtin `StrEnum` is not available
until Python 3.11.
"""

def __str__(self):
"""
Regular Enum's __str__ is the name, rather than the value,
e.g.
>>> str(Chain.MAINNET)
'Chain.MAINNET'
so we need to explicit use the value.
This behaves like the builtin `StrEnum` (available in 3.11).
"""
return str.__str__(self)


class Chain(StrEnum):
"""Identifiers for chains & layer 2s."""

MAINNET = "mainnet"
ARBITRUM = "arbitrum"
OPTIMISM = "optimism"
Expand All @@ -11,6 +37,8 @@ class Chain(str, Enum):
XDAI = "xdai"


class Env(str, Enum):
class Env(StrEnum):
"""Names for different API environments."""

PROD = "prod"
STAGING = "staging"

0 comments on commit c366426

Please sign in to comment.