Skip to content
Myr

Merge pull request #1517 from stgraham2000/master

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

authored by David Lord · committed by GitHub · parents 4aabded, 6472e3e · Browse files · 3 files+12 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

3 files+12 added−6 removed

  • tests:+7 added−0 removed
  • other:+5 added−6 removed

3 files+12 added−6 removed

modified:src/click/termui.py+2 added-6 removed
14 unmodified lines
15from .exceptions import UsageError16from .globals import resolve_color_default17from .types import Choice18from .types import convert_type19from .types import Path19from .utils import echo20from .utils import LazyFile2122# The prompt functions to use. The doc tools currently override these
121 unmodified lines
144 value = prompt_func(prompt)145 if value:146 break147 elif default is not None:149 if isinstance(value_proc, Path):150 # validate Path default value(exists, dir_okay etc.)151 value = default152 break148 value = default149 break153 return default150 try:151 result = value_proc(value)152 except UsageError as e:153 if hide_input:
581 unmodified lines
modified:tests/test_utils.py+7 added
208 unmodified lines
209 out, err = capfd.readouterr()210 assert out == f"{text}\n"211212213def test_prompt_cast_default(capfd, monkeypatch):214 monkeypatch.setattr(sys, "stdin", StringIO("\n"))215 value = click.prompt("value", default="100", type=int)216 capfd.readouterr()217 assert type(value) is int218219220@pytest.mark.skipif(WIN, reason="Test too complex to make work windows.")221def test_echo_writing_to_standard_error(capfd, monkeypatch):222 def emulate_input(text):223 """Emulate keyboard input."""
200 unmodified lines
modified:CHANGES.rst+3 added
143 unmodified lines
144 ``is_flag=False``, and the value can instead be prompted for or145 passed in as a default value.146 :issue:`549, 736, 764, 921, 1015, 1618`147- Fix formatting when ``Command.options_metavar`` is empty. :pr:`1551`148- The default value passed to ``prompt`` will be cast to the correct149 type like an input value would be. :pr:`1517`150151152Version 7.1.2153-------------154155Released 2020-04-27
633 unmodified lines