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