-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revert ignore_case deprecation from 13.0.0 #386
Comments
It's not documented (yet), but you can pass import os
from enum import StrEnum, auto
from environs import env
os.environ["COLOR"] = "red"
class Color(StrEnum):
RED = auto()
COLOR = env.enum("COLOR", enum=Color, by_value=True)
assert isinstance(COLOR, Color)
assert COLOR == Color.RED
print(COLOR) # => "red" @Mogost does this meet your use case? |
@sloria, this meets my case; thank you. Unfortunately, I cannot use it; mypy is not satisfied with that.
|
@sloria thank you! Also one offtop question. Is this usage of the "default" argument correct in the new version? (especially
|
@Mogost you'll need to change TENANT_ID = env.str(
"TENANT_ID",
default=default_tenant_id_by_instance_type.get(INSTANCE_TYPE) or Ellipsis,
validate=Regexp(r"^[a-zA-Z0-9_-]+$", error="TENANT_ID must contain only letters, numbers, underscores, and dashes"),
).lower() |
14.1.0 is released with the by_value fix, so closing this |
Hey @sloria , long time no chat 👋 Thanks for this awesome library. Unfortunately the removal of |
oh hello @maximz 👋 i'm hesitant to add a special case in the codebase to resurrect if your envvar casing differs from the enum name casing, you could do something like this import os
from dataclasses import dataclass
from enum import Enum
from environs import env, validate
# Envvar uses lowercase names
os.environ["ANIMAL"] = "dog"
@dataclass
class AnimalConfig:
genus: str
# Enum uses uppercase names
class Animal(Enum):
DOG = AnimalConfig("Canis")
CAT = AnimalConfig("Felis")
animal_config_name = env.str("ANIMAL", validate=validate.OneOf({v.name.lower() for v in Animal}))
animal_config = Animal[animal_config_name.upper()]
print(animal_config.value.genus) # Canis |
@sloria Sounds good — thanks for the quick reply and suggested workaround! Love the new singleton |
great! glad it works for you |
Version 13.0.0 was introduced Backwards-incompatible change
This change makes usage less convenient. Additionally, environs only respects enum "keys", not values, which seems illogical in many cases because values often represent the actual data being used in comparisons or user inputs, while keys are more like internal identifiers.
The text was updated successfully, but these errors were encountered: