Coverage for docs_src / options_autocompletion / tutorial005_py39.py: 100%
10 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-02-09 12:36 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-02-09 12:36 +0000
1import typer 1abcdefgh
3valid_completion_items = [ 1abcdefgh
4 ("Camila", "The reader of books."),
5 ("Carlos", "The writer of scripts."),
6 ("Sebastian", "The type hints guy."),
7]
10def complete_name(incomplete: str): 1abcdefgh
11 for name, help_text in valid_completion_items: 1abcdefgh
12 if name.startswith(incomplete): 1abcdefgh
13 yield (name, help_text) 1abcdefgh
16app = typer.Typer() 1abcdefgh
19@app.command() 1abcdefgh
20def main( 1abcdefgh
21 name: str = typer.Option(
22 "World", help="The name to say hi to.", autocompletion=complete_name
23 ),
24):
25 print(f"Hello {name}") 1abcdefgh
28if __name__ == "__main__": 1abcdefgh
29 app() 1abcdefgh