Coverage for docs_src / options_autocompletion / tutorial004_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 

3valid_completion_items = [ 1abcdefghij

4 ("Camila", "The reader of books."), 

5 ("Carlos", "The writer of scripts."), 

6 ("Sebastian", "The type hints guy."), 

7] 

8 

9 

10def complete_name(incomplete: str): 1abcdefghij

11 completion = [] 1abcdefghij

12 for name, help_text in valid_completion_items: 1abcdefghij

13 if name.startswith(incomplete): 1abcdefghij

14 completion_item = (name, help_text) 1abcdefghij

15 completion.append(completion_item) 1abcdefghij

16 return completion 1abcdefghij

17 

18 

19app = typer.Typer() 1abcdefghij

20 

21 

22@app.command() 1abcdefghij

23def main( 1abcdefghij

24 name: str = typer.Option( 

25 "World", help="The name to say hi to.", autocompletion=complete_name 

26 ), 

27): 

28 print(f"Hello {name}") 1abcdefghij

29 

30 

31if __name__ == "__main__": 1abcdefghij

32 app() 1abcdefghij