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