Coverage for docs_src/options_autocompletion/tutorial004_an.py: 100%
14 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-19 20:29 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-19 20:29 +0000
1import typer 1abcdefghi
2from typing_extensions import Annotated 1abcdefghi
4valid_completion_items = [ 1abcdefghi
5 ("Camila", "The reader of books."),
6 ("Carlos", "The writer of scripts."),
7 ("Sebastian", "The type hints guy."),
8]
11def complete_name(incomplete: str): 1abcdefghi
12 completion = [] 1abcdefghi
13 for name, help_text in valid_completion_items: 1abcdefghi
14 if name.startswith(incomplete): 1abcdefghi
15 completion_item = (name, help_text) 1abcdefghi
16 completion.append(completion_item) 1abcdefghi
17 return completion 1abcdefghi
20app = typer.Typer() 1abcdefghi
23@app.command() 1abcdefghi
24def main( 1abcdefghi
25 name: Annotated[
26 str, typer.Option(help="The name to say hi to.", autocompletion=complete_name)
27 ] = "World",
28):
29 print(f"Hello {name}") 1abcdefghi
32if __name__ == "__main__": 1abcdefghi
33 app() 1abcdefghi