Coverage for docs_src/parameter_types/custom_types/tutorial001_an.py: 100%
12 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-04-14 00:18 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-04-14 00:18 +0000
1import typer 1iabcdefgh
2from typing_extensions import Annotated 1iabcdefgh
5class CustomClass: 1iabcdefgh
6 def __init__(self, value: str): 1iabcdefgh
7 self.value = value 1iabcdefgh
9 def __str__(self): 1iabcdefgh
10 return f"<CustomClass: value={self.value}>" 1iabcdefgh
13def parse_custom_class(value: str): 1iabcdefgh
14 return CustomClass(value * 2) 1iabcdefgh
17def main( 1abcdefgh
18 custom_arg: Annotated[CustomClass, typer.Argument(parser=parse_custom_class)],
19 custom_opt: Annotated[CustomClass, typer.Option(parser=parse_custom_class)] = "Foo",
20):
21 print(f"custom_arg is {custom_arg}") 1iabcdefgh
22 print(f"--custom-opt is {custom_opt}") 1iabcdefgh
25if __name__ == "__main__": 1iabcdefgh
26 typer.run(main) 1iabcdefgh