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

13 statements  

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

1import typer 1abcdefghij

2 

3 

4class CustomClass: 1abcdefghij

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

6 self.value = value 1abcdefghij

7 

8 def __str__(self): 1abcdefghij

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

10 

11 

12def parse_custom_class(value: str): 1abcdefghij

13 return CustomClass(value * 2) 1abcdefghij

14 

15 

16app = typer.Typer() 1abcdefghij

17 

18 

19@app.command() 1abcdefghij

20def main( 1abcdefghij

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}") 1abcdefghij

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

26 

27 

28if __name__ == "__main__": 1abcdefghij

29 app() 1abcdefghij