Coverage for docs_src / options_autocompletion / tutorial007_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_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(ctx: typer.Context, incomplete: str): 1abcdefgh
11 names = ctx.params.get("name") or [] 1abcdefgh
12 for name, help_text in valid_completion_items: 1abcdefgh
13 if name.startswith(incomplete) and name not in names: 1abcdefgh
14 yield (name, help_text) 1abcdefgh
17app = typer.Typer() 1abcdefgh
20@app.command() 1abcdefgh
21def main( 1abcdefgh
22 name: list[str] = typer.Option(
23 ["World"], help="The name to say hi to.", autocompletion=complete_name
24 ),
25):
26 for n in name: 1abcdefgh
27 print(f"Hello {n}") 1abcdefgh
30if __name__ == "__main__": 1abcdefgh
31 app() 1abcdefgh