Defining different values to an enum according to a condition in python

458 views Asked by At

I'm dealing with an "apparently" simple problem with enums in Python that i cannot figure out how to solve. I just need to load different values for an enum in different environments (dev and prod). Ex:

in dev environment I`d like to define:

from enum import Enum

class PortsDev(Enum):
    service_1 = 5000
    service_2 = 5001
 

in prod environment I`d like to define:

from enum import Enum

class Ports(Enum):
    service_1 = 3000
    service_2 = 3001
 

I'm using conditional import, as:

if os.getenv("APPLICATION_CONFIG") == "production":
    from .services_ports import Ports
else:
    from .services_ports import PortsDev as Ports 

It works, but, the pre-commit fails on mypy with error.

Does anyone have a suggestion for a better way to do this?

Thanks in advance

0

There are 0 answers