Coverage for docs_src/options_autocompletion/tutorial003.py: 100%
12 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_names = ["Camila", "Carlos", "Sebastian"] 1iabcdefgh
6def complete_name(incomplete: str): 1iabcdefgh
7 completion = [] 1iabcdefgh
8 for name in valid_names: 1iabcdefgh
9 if name.startswith(incomplete): 1iabcdefgh
10 completion.append(name) 1iabcdefgh
11 return completion 1iabcdefgh
14app = typer.Typer() 1iabcdefgh
17@app.command() 1iabcdefgh
18def main( 1abcdefgh
19 name: str = typer.Option(
20 "World", help="The name to say hi to.", autocompletion=complete_name
21 ),
22):
23 print(f"Hello {name}") 1iabcdefgh
26if __name__ == "__main__": 1iabcdefgh
27 app() 1iabcdefgh