Coverage for docs_src / parameter_types / custom_types / tutorial001.py: 100%
14 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-11-18 11:12 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-11-18 11:12 +0000
1from typing import Annotated 1abcdefghij
3import typer 1abcdefghij
6class CustomClass: 1abcdefghij
7 def __init__(self, value: str): 1abcdefghij
8 self.value = value 1abcdefghij
10 def __str__(self): 1abcdefghij
11 return f"<CustomClass: value={self.value}>" 1abcdefghij
14def parse_custom_class(value: str): 1abcdefghij
15 return CustomClass(value * 2) 1abcdefghij
18app = typer.Typer() 1abcdefghij
21@app.command() 1abcdefghij
22def main( 1abcdefghij
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}") 1abcdefghij
27 print(f"--custom-opt is {custom_opt}") 1abcdefghij
30if __name__ == "__main__": 1abcdefghij
31 app() 1abcdefghij