Enum values that differ in case get conflated #570
Answered
by
avaldebe
krzysztofwos
asked this question in
Questions
-
First Check
Commit to Help
Example Codefrom enum import Enum
import typer
class Interval(Enum):
ONE_MINUTE = "1m"
ONE_MONTH = "1M"
def main(interval: Interval = typer.Argument("1m", case_sensitive=True)):
print(interval)
if __name__ == "__main__":
typer.run(main) DescriptionThe example illustrates the problem: enum values that differ in case get conflated. In the example above, running the script with def generate_enum_convertor(enum: Type[Enum]) -> Callable[[Any], Any]:
lower_val_map = {str(val.value).lower(): val for val in enum}
def convertor(value: Any) -> Any:
if value is not None:
low = str(value).lower()
if low in lower_val_map:
key = lower_val_map[low]
return enum(key)
return convertor Operating SystemLinux Operating System DetailsNo response Typer Version0.7.0 Python Version3.10.6 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Answered by
avaldebe
Mar 21, 2023
Replies: 1 comment 1 reply
-
This is a bug 🐞, IMO. I submitted a PR to fix it #571. Hope it gets merged... |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
svlandeg
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a bug 🐞, IMO. I submitted a PR to fix it #571. Hope it gets merged...