Skip to content
Myr

🐛 Fix PowerShell completion with incomplete word (#360)

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

authored by patricksurry · committed by GitHub · parent 3f566ed · Browse files · 3 files+37 added−3 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: Sebastián Ramírez <tiangolo@gmail.com>
  • Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Co-authored-by: svlandeg <svlandeg@github.com>

Diff stats

3 files+37 added−3 removed

  • tests:+36 added−2 removed
  • other:+1 added−1 removed

3 files+37 added−3 removed

modified:tests/test_tutorial/test_options_autocompletion/test_tutorial003_an.py+18 added-1 removed
7 unmodified lines
89runner = CliRunner()101112def test_completion():12def test_completion_zsh():13 result = subprocess.run(14 [sys.executable, "-m", "coverage", "run", mod.__file__, " "],15 capture_output=True,16 encoding="utf-8",
7 unmodified lines
24 assert "Carlos" not in result.stdout25 assert "Sebastian" in result.stdout262728def test_completion_powershell():29 result = subprocess.run(30 [sys.executable, "-m", "coverage", "run", mod.__file__, " "],31 capture_output=True,32 encoding="utf-8",33 env={34 **os.environ,35 "_TUTORIAL003_AN.PY_COMPLETE": "complete_powershell",36 "_TYPER_COMPLETE_ARGS": "tutorial003.py --name Seb",37 "_TYPER_COMPLETE_WORD_TO_COMPLETE": "Seb",38 },39 )40 assert "Camila" not in result.stdout41 assert "Carlos" not in result.stdout42 assert "Sebastian" in result.stdout434445def test_1():46 result = runner.invoke(mod.app, ["--name", "Camila"])47 assert result.exit_code == 048 assert "Hello Camila" in result.output
9 unmodified lines
modified:tests/test_tutorial/test_options_autocompletion/test_tutorial003.py+18 added-1 removed
7 unmodified lines
89runner = CliRunner()101112def test_completion():12def test_completion_zsh():13 result = subprocess.run(14 [sys.executable, "-m", "coverage", "run", mod.__file__, " "],15 capture_output=True,16 encoding="utf-8",
7 unmodified lines
24 assert "Carlos" not in result.stdout25 assert "Sebastian" in result.stdout262728def test_completion_powershell():29 result = subprocess.run(30 [sys.executable, "-m", "coverage", "run", mod.__file__, " "],31 capture_output=True,32 encoding="utf-8",33 env={34 **os.environ,35 "_TUTORIAL003.PY_COMPLETE": "complete_powershell",36 "_TYPER_COMPLETE_ARGS": "tutorial003.py --name Seb",37 "_TYPER_COMPLETE_WORD_TO_COMPLETE": "Seb",38 },39 )40 assert "Camila" not in result.stdout41 assert "Carlos" not in result.stdout42 assert "Sebastian" in result.stdout434445def test_1():46 result = runner.invoke(mod.app, ["--name", "Camila"])47 assert result.exit_code == 048 assert "Hello Camila" in result.output
9 unmodified lines
modified:typer/_completion_classes.py+1 added-1 removed
173 unmodified lines
174 def get_completion_args(self) -> Tuple[List[str], str]:175 completion_args = os.getenv("_TYPER_COMPLETE_ARGS", "")176 incomplete = os.getenv("_TYPER_COMPLETE_WORD_TO_COMPLETE", "")177 cwords = click.parser.split_arg_string(completion_args)178 args = cwords[1:]178 args = cwords[1:-1] if incomplete else cwords[1:]179 return args, incomplete180181 def format_completion(self, item: click.shell_completion.CompletionItem) -> str:182 return f"{item.value}:::{item.help or ' '}"
10 unmodified lines