Coverage for typer / _types.py: 100%
12 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-03-26 21:46 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-03-26 21:46 +0000
1from enum import Enum 1abcdefg
2from typing import TypeVar 1abcdefg
4import click 1abcdefg
6ParamTypeValue = TypeVar("ParamTypeValue") 1abcdefg
9class TyperChoice(click.Choice[ParamTypeValue]): 1abcdefg
10 def normalize_choice( 1abcdefg
11 self, choice: ParamTypeValue, ctx: click.Context | None
12 ) -> str:
13 # Click 8.2.0 added a new method `normalize_choice` to the `Choice` class
14 # to support enums, but it uses the enum names, while Typer has always used the
15 # enum values.
16 # This class overrides that method to maintain the previous behavior.
17 # In Click:
18 # normed_value = choice.name if isinstance(choice, Enum) else str(choice)
19 normed_value = str(choice.value) if isinstance(choice, Enum) else str(choice) 1abcdefg
21 if ctx is not None and ctx.token_normalize_func is not None: 1abcdefg
22 normed_value = ctx.token_normalize_func(normed_value) 1abcdefg
24 if not self.case_sensitive: 1abcdefg
25 normed_value = normed_value.casefold() 1abcdefg
27 return normed_value 1abcdefg