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

11 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-04-14 00:18 +0000

1import typer 1iabcdefgh

2 

3 

4class CustomClass: 1iabcdefgh

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

6 self.value = value 1iabcdefgh

7 

8 def __str__(self): 1iabcdefgh

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

10 

11 

12def parse_custom_class(value: str): 1iabcdefgh

13 return CustomClass(value * 2) 1iabcdefgh

14 

15 

16def main( 1abcdefgh

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

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

19): 

20 print(f"custom_arg is {custom_arg}") 1iabcdefgh

21 print(f"--custom-opt is {custom_opt}") 1iabcdefgh

22 

23 

24if __name__ == "__main__": 1iabcdefgh

25 typer.run(main) 1iabcdefgh