Coverage for docs_src / parameter_types / custom_types / tutorial001_an_py39.py: 100%
14 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 typing import Annotated 1abcdefgh
3import typer 1abcdefgh
6class CustomClass: 1abcdefgh
7 def __init__(self, value: str): 1abcdefgh
8 self.value = value 1abcdefgh
10 def __str__(self): 1abcdefgh
11 return f"<CustomClass: value={self.value}>" 1abcdefgh
14def parse_custom_class(value: str): 1abcdefgh
15 return CustomClass(value * 2) 1abcdefgh
18app = typer.Typer() 1abcdefgh
21@app.command() 1abcdefgh
22def main( 1abcdefgh
23 custom_arg: Annotated[CustomClass, typer.Argument(parser=parse_custom_class)],
24 custom_opt: Annotated[CustomClass, typer.Option(parser=parse_custom_class)] = "Foo",
25):
26 print(f"custom_arg is {custom_arg}") 1abcdefgh
27 print(f"--custom-opt is {custom_opt}") 1abcdefgh
30if __name__ == "__main__": 1abcdefgh
31 app() 1abcdefgh