Coverage for typer / _types.py: 100%
12 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-02-09 12:36 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-02-09 12:36 +0000
1from enum import Enum 1abchdefg
2from typing import Generic, TypeVar, Union 1abchdefg
4import click 1abchdefg
6ParamTypeValue = TypeVar("ParamTypeValue") 1abchdefg
9class TyperChoice(click.Choice, Generic[ParamTypeValue]): # type: ignore[type-arg] 1abchdefg
10 def normalize_choice( 1abchdefg
11 self, choice: ParamTypeValue, ctx: Union[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