Coverage for docs_src / options_autocompletion / tutorial004_an_py39.py: 100%
14 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
1from typing import Annotated 1abcdefgh
3import typer 1abcdefgh
5valid_completion_items = [ 1abcdefgh
6 ("Camila", "The reader of books."),
7 ("Carlos", "The writer of scripts."),
8 ("Sebastian", "The type hints guy."),
9]
12def complete_name(incomplete: str): 1abcdefgh
13 completion = [] 1abcdefgh
14 for name, help_text in valid_completion_items: 1abcdefgh
15 if name.startswith(incomplete): 1abcdefgh
16 completion_item = (name, help_text) 1abcdefgh
17 completion.append(completion_item) 1abcdefgh
18 return completion 1abcdefgh
21app = typer.Typer() 1abcdefgh
24@app.command() 1abcdefgh
25def main( 1abcdefgh
26 name: Annotated[
27 str, typer.Option(help="The name to say hi to.", autocompletion=complete_name)
28 ] = "World",
29):
30 print(f"Hello {name}") 1abcdefgh
33if __name__ == "__main__": 1abcdefgh
34 app() 1abcdefgh