Coverage for docs_src/options_autocompletion/tutorial004.py: 100%
13 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-04-14 00:18 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-04-14 00:18 +0000
1import typer 1iabcdefgh
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): 1iabcdefgh
11 completion = [] 1iabcdefgh
12 for name, help_text in valid_completion_items: 1iabcdefgh
13 if name.startswith(incomplete): 1iabcdefgh
14 completion_item = (name, help_text) 1iabcdefgh
15 completion.append(completion_item) 1iabcdefgh
16 return completion 1iabcdefgh
19app = typer.Typer() 1iabcdefgh
22@app.command() 1iabcdefgh
23def main( 1abcdefgh
24 name: str = typer.Option(
25 "World", help="The name to say hi to.", autocompletion=complete_name
26 ),
27):
28 print(f"Hello {name}") 1iabcdefgh
31if __name__ == "__main__": 1iabcdefgh
32 app() 1iabcdefgh