Coverage for docs_src / parameter_types / custom_types / tutorial002_py39.py: 100%
16 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
1import click 1abcdefgh
2import typer 1abcdefgh
5class CustomClass: 1abcdefgh
6 def __init__(self, value: str): 1abcdefgh
7 self.value = value 1abcdefgh
9 def __repr__(self): 1abcdefgh
10 return f"<CustomClass: value={self.value}>" 1abcdefgh
13class CustomClassParser(click.ParamType): 1abcdefgh
14 name = "CustomClass" 1abcdefgh
16 def convert(self, value, param, ctx): 1abcdefgh
17 return CustomClass(value * 3) 1abcdefgh
20app = typer.Typer() 1abcdefgh
23@app.command() 1abcdefgh
24def main( 1abcdefgh
25 custom_arg: CustomClass = typer.Argument(click_type=CustomClassParser()),
26 custom_opt: CustomClass = typer.Option("Foo", click_type=CustomClassParser()),
27):
28 print(f"custom_arg is {custom_arg}") 1abcdefgh
29 print(f"--custom-opt is {custom_opt}") 1abcdefgh
32if __name__ == "__main__": 1abcdefgh
33 app() 1abcdefgh