Coverage for docs_src / options_autocompletion / tutorial009_non_an.py: 100%
15 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-11-18 11:12 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-11-18 11:12 +0000
1import typer 1abcdefghij
2from rich.console import Console 1abcdefghij
4valid_completion_items = [ 1abcdefghij
5 ("Camila", "The reader of books."),
6 ("Carlos", "The writer of scripts."),
7 ("Sebastian", "The type hints guy."),
8]
10err_console = Console(stderr=True) 1abcdefghij
13def complete_name(ctx: typer.Context, args: list[str], incomplete: str): 1abcdefghij
14 err_console.print(f"{args}") 1abcdefghij
15 names = ctx.params.get("name") or [] 1abcdefghij
16 for name, help_text in valid_completion_items: 1abcdefghij
17 if name.startswith(incomplete) and name not in names: 1abcdefghij
18 yield (name, help_text) 1abcdefghij
21app = typer.Typer() 1abcdefghij
24@app.command() 1abcdefghij
25def main( 1abcdefghij
26 name: list[str] = typer.Option(
27 ["World"], help="The name to say hi to.", autocompletion=complete_name
28 ),
29):
30 for n in name: 1abcdefghij
31 print(f"Hello {n}") 1abcdefghij
34if __name__ == "__main__": 1abcdefghij
35 app() 1abcdefghij