Skip to content
Myr

type is always IOBase, handle lazy file

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

authored by David Lord · committed by David Lord · parent 2ddc9af · Browse files · 5 files+22 added−18 removed
This commit

State

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

Diff stats

5 files+22 added−18 removed

  • tests:+14 added−12 removed
  • other:+8 added−6 removed

5 files+22 added−18 removed

modified:click/_compat.py-2 removed
154 unmodified lines
155156157if PY2:158 text_type = unicode159 file_type = file159 raw_input = raw_input160 string_types = (str, unicode)161 int_types = (int, long)162 iteritems = lambda x: x.iteritems()
97 unmodified lines
260 return value261else:262 import io263 text_type = str265 file_type = io.TextIOWrapper264 raw_input = input265 string_types = (str,)266 int_types = (int,)267 range_type = range
503 unmodified lines
modified:click/termui.py+6 added-3 removed
1import io2import os3import sys4import struct5import inspect6import itertools78from ._compat import raw_input, text_type, string_types, \8 isatty, strip_ansi, get_winterm_size, DEFAULT_COLUMNS, WIN, file_type9 isatty, strip_ansi, get_winterm_size, DEFAULT_COLUMNS, WIN10from .utils import echo11from .exceptions import Abort, UsageError12from .types import convert_type, Choice, Path13from .globals import resolve_color_default14from .utils import LazyFile151617# The prompt functions to use. The doc tools currently override these18# functions to customize how they work.
35 unmodified lines
54 return prompt + suffix555657def _format_default(default):56 if isinstance(default, file_type):57 default = default.name58 if isinstance(default, (io.IOBase, LazyFile)) and hasattr(default, "name"):59 return default.name6061 return default626364def prompt(text, default=None, hide_input=False, confirmation_prompt=False,
557 unmodified lines
deleted:tests/static/config.json-3 removed
modified:tests/test_termui.py+14 added-9 removed
1 unmodified line
2import pytest34import click5import time6import os67import click._termui_impl8from click._compat import WIN9
214 unmodified lines
224 result = runner.invoke(cli_without_choices, [], input='none')225 assert '(none, day, week, month)' not in result.output226227229def test_default_prompt_format(runner):230 path_default = os.path.join(os.path.dirname(__file__), "static/config.json")231228@pytest.mark.parametrize(229 "file_kwargs",230 [231 {"mode": "rt"},232 {"mode": "rb"},233 {"lazy": True},234 ]235)236def test_file_prompt_default_format(runner, file_kwargs):237 @click.command()233 @click.option('-f', default=path_default, prompt='file', type=click.File('r'))234 def cli_with_text_io_wrapper_default(f):235 pass238 @click.option("-f", default=__file__, prompt="file", type=click.File(**file_kwargs))239 def cli(f):240 click.echo(f.name)241237 result = runner.invoke(cli_with_text_io_wrapper_default, [])238 assert result.output == 'file [%s]: \n' % path_default242 result = runner.invoke(cli)243 assert result.output == "file [{0}]: \n{0}\n".format(__file__)244245246def test_secho(runner):247 with runner.isolation() as outstreams:
66 unmodified lines
modified:CHANGES.rst+2 added-1 removed
40 unmodified lines
41- Newlines in option help text are replaced with spaces before42 re-wrapping to avoid uneven line breaks. :issue:`834`43- ``MissingParameter`` exceptions are printable in the Python44 interpreter. :issue:`1139`45- File option prompting now displays path only. :issue:`914`45- Fix how default values for file-type options are shown during46 prompts. :issue:`914`474849Version 7.050-----------
540 unmodified lines