Coverage for docs_src / parameter_types / custom_types / tutorial001_py39.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-02-09 12:36 +0000

1import typer 1abcdefgh

2 

3 

4class CustomClass: 1abcdefgh

5 def __init__(self, value: str): 1abcdefgh

6 self.value = value 1abcdefgh

7 

8 def __str__(self): 1abcdefgh

9 return f"<CustomClass: value={self.value}>" 1abcdefgh

10 

11 

12def parse_custom_class(value: str): 1abcdefgh

13 return CustomClass(value * 2) 1abcdefgh

14 

15 

16app = typer.Typer() 1abcdefgh

17 

18 

19@app.command() 1abcdefgh

20def main( 1abcdefgh

21 custom_arg: CustomClass = typer.Argument(parser=parse_custom_class), 

22 custom_opt: CustomClass = typer.Option("Foo", parser=parse_custom_class), 

23): 

24 print(f"custom_arg is {custom_arg}") 1abcdefgh

25 print(f"--custom-opt is {custom_opt}") 1abcdefgh

26 

27 

28if __name__ == "__main__": 1abcdefgh

29 app() 1abcdefgh