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

13 statements  

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

1from typing import Annotated 1abcdefgh

2 

3import typer 1abcdefgh

4 

5valid_names = ["Camila", "Carlos", "Sebastian"] 1abcdefgh

6 

7 

8def complete_name(incomplete: str): 1abcdefgh

9 completion = [] 1abcdefgh

10 for name in valid_names: 1abcdefgh

11 if name.startswith(incomplete): 1abcdefgh

12 completion.append(name) 1abcdefgh

13 return completion 1abcdefgh

14 

15 

16app = typer.Typer() 1abcdefgh

17 

18 

19@app.command() 1abcdefgh

20def main( 1abcdefgh

21 name: Annotated[ 

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

23 ] = "World", 

24): 

25 print(f"Hello {name}") 1abcdefgh

26 

27 

28if __name__ == "__main__": 1abcdefgh

29 app() 1abcdefgh