Coverage for docs_src / options_autocompletion / tutorial005.py: 100%

11 statements  

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

1from typing import Annotated 1abcdefghij

2 

3import typer 1abcdefghij

4 

5valid_completion_items = [ 1abcdefghij

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

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

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

9] 

10 

11 

12def complete_name(incomplete: str): 1abcdefghij

13 for name, help_text in valid_completion_items: 1abcdefghij

14 if name.startswith(incomplete): 1abcdefghij

15 yield (name, help_text) 1abcdefghij

16 

17 

18app = typer.Typer() 1abcdefghij

19 

20 

21@app.command() 1abcdefghij

22def main( 1abcdefghij

23 name: Annotated[ 

24 str, typer.Option(help="The name to say hi to.", autocompletion=complete_name) 

25 ] = "World", 

26): 

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

28 

29 

30if __name__ == "__main__": 1abcdefghij

31 app() 1abcdefghij