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

13 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_names = ["Camila", "Carlos", "Sebastian"] 1abcdefghij

6 

7 

8def complete_name(incomplete: str): 1abcdefghij

9 completion = [] 1abcdefghij

10 for name in valid_names: 1abcdefghij

11 if name.startswith(incomplete): 1abcdefghij

12 completion.append(name) 1abcdefghij

13 return completion 1abcdefghij

14 

15 

16app = typer.Typer() 1abcdefghij

17 

18 

19@app.command() 1abcdefghij

20def main( 1abcdefghij

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

26 

27 

28if __name__ == "__main__": 1abcdefghij

29 app() 1abcdefghij