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