Coverage for docs_src / options_autocompletion / tutorial003_py39.py: 100%
12 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
1import typer 1abcdefgh
3valid_names = ["Camila", "Carlos", "Sebastian"] 1abcdefgh
6def complete_name(incomplete: str): 1abcdefgh
7 completion = [] 1abcdefgh
8 for name in valid_names: 1abcdefgh
9 if name.startswith(incomplete): 1abcdefgh
10 completion.append(name) 1abcdefgh
11 return completion 1abcdefgh
14app = typer.Typer() 1abcdefgh
17@app.command() 1abcdefgh
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}") 1abcdefgh
26if __name__ == "__main__": 1abcdefgh
27 app() 1abcdefgh