Skip to content
Myr

🐛 Fix preserving case in enum values (#571)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Alvaro Valdebenito · committed by GitHub · parent 74433d2 · Browse files · 3 files+28 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: svlandeg <svlandeg@github.com>
  • Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

Diff stats

3 files+28 added−5 removed

  • tests:+16 added−1 removed
  • other:+12 added−4 removed

3 files+28 added−5 removed

modified:docs/tutorial/parameter-types/enum.md+8 added
modified:tests/test_tutorial/test_parameter_types/test_enum/test_tutorial001.py+16 added-1 removed
23 unmodified lines
24 assert result.exit_code == 025 assert "Training neural network of type: conv" in result.output262728def test_invalid():28def test_invalid_case():29 result = runner.invoke(app, ["--network", "CONV"])30 assert result.exit_code != 031 # TODO: when deprecating Click 7, remove second option3233 assert (34 "Invalid value for '--network': 'CONV' is not one of" in result.output35 or "Invalid value for '--network': invalid choice: CONV. (choose from"36 in result.output37 )38 assert "simple" in result.output39 assert "conv" in result.output40 assert "lstm" in result.output414243def test_invalid_other():44 result = runner.invoke(app, ["--network", "capsule"])45 assert result.exit_code != 046 # TODO: when deprecating Click 7, remove second option47
18 unmodified lines
modified:typer/main.py+4 added-4 removed
616 unmodified lines
617 return None618619620def generate_enum_convertor(enum: Type[Enum]) -> Callable[[Any], Any]:621 lower_val_map = {str(val.value).lower(): val for val in enum}621 val_map = {str(val.value): val for val in enum}622623 def convertor(value: Any) -> Any:624 if value is not None:625 low = str(value).lower()626 if low in lower_val_map:627 key = lower_val_map[low]625 val = str(value)626 if val in val_map:627 key = val_map[val]628 return enum(key)629630 return convertor631
425 unmodified lines