Skip to content
Myr

🐛 Fix `shell_complete` not working for Arguments (#737)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Brian Kohan · committed by GitHub · parent 76ca3e3 · Browse files · 3 files+42 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: svlandeg <svlandeg@github.com>

Diff stats

3 files+42 added−0 removed

  • tests:+41 added−0 removed
  • other:+1 added−0 removed

3 files+42 added−0 removed

added:tests/assets/completion_argument.py+22 added
1import click2import typer34app = typer.Typer()567def shell_complete(ctx: click.Context, param: click.Parameter, incomplete: str):8 typer.echo(f"ctx: {ctx.info_name}", err=True)9 typer.echo(f"arg is: {param.name}", err=True)10 typer.echo(f"incomplete is: {incomplete}", err=True)11 return ["Emma"]121314@app.command(context_settings={"auto_envvar_prefix": "TEST"})15def main(name: str = typer.Argument(shell_complete=shell_complete)):16 """17 Say hello.18 """192021if __name__ == "__main__":22 app()
modified:tests/test_others.py+19 added
139 unmodified lines
140 assert "param name is: name" in result.stdout141 assert "value is: Camila" in result.stdout142143144def test_completion_argument():145 file_path = Path(__file__).parent / "assets/completion_argument.py"146 result = subprocess.run(147 [sys.executable, "-m", "coverage", "run", str(file_path), "E"],148 capture_output=True,149 encoding="utf-8",150 env={151 **os.environ,152 "_COMPLETION_ARGUMENT.PY_COMPLETE": "complete_zsh",153 "_TYPER_COMPLETE_ARGS": "completion_argument.py E",154 "_TYPER_COMPLETE_TESTING": "True",155 },156 )157 assert "Emma" in result.stdout or "_files" in result.stdout158 assert "ctx: completion_argument" in result.stderr159 assert "arg is: name" in result.stderr160 assert "incomplete is: E" in result.stderr161162163def test_completion_untyped_parameters():164 file_path = Path(__file__).parent / "assets/completion_no_types.py"165 result = subprocess.run(166 [sys.executable, "-m", "coverage", "run", str(file_path)],
111 unmodified lines
modified:typer/main.py+1 added
945 unmodified lines
946 metavar=parameter_info.metavar,947 expose_value=parameter_info.expose_value,948 is_eager=parameter_info.is_eager,949 envvar=parameter_info.envvar,950 shell_complete=parameter_info.shell_complete,951 autocompletion=get_param_completion(parameter_info.autocompletion),952 # Rich settings953 rich_help_panel=parameter_info.rich_help_panel,954 ),
114 unmodified lines