Coverage for docs_src/options_autocompletion/tutorial003_an.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
2from typing_extensions import Annotated 1iabcdefgh
4valid_names = ["Camila", "Carlos", "Sebastian"] 1iabcdefgh
7def complete_name(incomplete: str): 1iabcdefgh
8 completion = [] 1iabcdefgh
9 for name in valid_names: 1iabcdefgh
10 if name.startswith(incomplete): 1iabcdefgh
11 completion.append(name) 1iabcdefgh
12 return completion 1iabcdefgh
15app = typer.Typer() 1iabcdefgh
18@app.command() 1iabcdefgh
19def main( 1abcdefgh
20 name: Annotated[
21 str, typer.Option(help="The name to say hi to.", autocompletion=complete_name)
22 ] = "World",
23):
24 print(f"Hello {name}") 1iabcdefgh
27if __name__ == "__main__": 1iabcdefgh
28 app() 1iabcdefgh