Merge stable into main (#3479)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Rowlando13 · committed by GitHub · parents 4e869f3, 9b327da · Browse files · 7 files·+32 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+32 added−6 removed
- tests:+23 added−1 removed
- other:+9 added−5 removed
Provenance
- Commit
dbf4d14- Tree
d8c539f- Author
Rowlando13 <67291205+Rowlando13@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent 1
4e869f3- Parent 2
9b327da
7 files changed+32 added−6 removed
modified:src/click/_compat.py+1 added
10 unmodified lines11 from weakref import WeakKeyDictionary12 13 CYGWIN = sys.platform.startswith("cygwin")14 WIN = sys.platform.startswith("win")15+MAC = sys.platform == "darwin"16 auto_wrap_for_ansi: t.Callable[[t.TextIO], t.TextIO] | None = None17 _ansi_re = re.compile(r"\033\[[;?0-9]*[a-zA-Z]")18 19 608 unmodified linesmodified:src/click/_termui_impl.py+1 added-1 removed
757 unmodified lines758 null.close()759 elif WIN:760 if locate:761 url = _unquote_file(url)762- args = ["explorer", f"/select,{url}"]762+ args = ["explorer", "/select,", url]763 try:764 return subprocess.call(args)765 except OSError:766 return 127143 unmodified linesmodified:src/click/shell_completion.py+3 added-2 removed
41 unmodified lines42 return 143 44 comp = comp_cls(cli, ctx_args, prog_name, complete_var)45 46+ # Write bytes, otherwise Windows text stdout translates LF to CRLF and breaks.47 if instruction == "source":47- echo(comp.source())48+ echo(comp.source().encode(), nl=False)49 return 050 51 if instruction == "complete":51- echo(comp.complete())52+ echo(comp.complete().encode())53 return 054 55 return 156 624 unmodified linesmodified:src/click/types.py+1 added-2 removed
406 unmodified lines407 .. versionadded:: 8.0408 """409 from click.shell_completion import CompletionItem410 411- str_choices = map(str, self.choices)412-411+ str_choices = [self.normalize_choice(choice, ctx) for choice in self.choices]412 if self.case_sensitive:413 matched = (c for c in str_choices if c.startswith(incomplete))414 else:415 incomplete = incomplete.lower()883 unmodified linesmodified:tests/test_shell_completion.py+18 added-1 removed
1+import io2 import textwrap3 import warnings4 from collections.abc import Mapping5 5 unmodified lines11 from click.core import Group12 from click.core import Option13 from click.shell_completion import add_completion_class14 from click.shell_completion import CompletionItem15+from click.shell_completion import shell_complete16 from click.shell_completion import ShellComplete17 from click.types import Choice18 from click.types import File19 from click.types import Path351 unmodified lines371 result = runner.invoke(cli, env=env)372 assert result.output == expect373 374 375+def test_source_uses_lf_line_endings(monkeypatch):376+ stdout = io.BytesIO()377+ stream = io.TextIOWrapper(stdout, encoding="utf-8", newline="\r\n")378+ monkeypatch.setattr("click.utils._default_text_stdout", lambda: stream)379+380+ cli = Group("cli", commands=[Command("a"), Command("b")])381+ assert shell_complete(cli, {}, "cli", "_CLI_COMPLETE", "zsh_source") == 0382+383+ stream.flush()384+ output = stdout.getvalue()385+ assert b"\r\n" not in output386+ assert b"\n" in output387+388+389 @pytest.mark.parametrize(390 ("env", "expect"),391 [392 (79 unmodified lines472 )473 assert result.output == "plain,a\nplain,b\n"474 475 476+# case_sensitive=False normalizes values to lowercase, matching remains case insensitive460-@pytest.mark.parametrize(("value", "expect"), [(False, ["Au", "al"]), (True, ["al"])])477+@pytest.mark.parametrize(("value", "expect"), [(False, ["au", "al"]), (True, ["al"])])478 def test_choice_case_sensitive(value, expect):479 cli = Command(480 "cli",481 params=[Option(["-a"], type=Choice(["Au", "al", "Bc"], case_sensitive=value))],144 unmodified linesmodified:tests/test_utils.py+5 added
13 unmodified lines14 import pytest15 16 import click._termui_impl17 import click.utils18+from click._compat import MAC19 from click._compat import WIN20 from click._utils import UNSET21 22 286 unmodified lines309 )310 311 312 @pytest.mark.skipif(WIN, reason="Different behavior on windows.")313+@pytest.mark.skipif(314+ MAC and sys.version_info >= (3, 13) and sys._is_gil_enabled(),315+ reason="Generator exception tests are flaky in Python 3.14t on macOS.",316+)317 @pytest.mark.parametrize(318 "pager_cmd", ["cat", "cat ", " cat ", "less", " less", " less "]319 )320 @pytest.mark.parametrize(467 unmodified linesmodified:CHANGES.rst+3 added
9 unmodified lines10 -------------11 12 Unreleased13 14+- Zsh completion scripts parse correctly on Windows. :issue:`3277`15+- Shell completion of `Choice` `Enum` values produces a valid completion16+ result. :issue:`3015`17 18 Version 8.4.019 -------------20 1462 unmodified lines