Skip to content
Myr

Merge pull request #1606 from andy-maier/andy/fix-trailing-blanks

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

boolean type strips space before converting

authored by David Lord · committed by GitHub · parents a11a5da, 0c1f7f0 · Browse files · 3 files+20 added−3 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+20 added−3 removed

  • tests:+11 added−0 removed
  • other:+9 added−3 removed

3 files+20 added−3 removed

modified:src/click/types.py+7 added-3 removed
495 unmodified lines
496497 def convert(self, value, param, ctx):498 if isinstance(value, bool):499 return bool(value)500 value = value.lower()501 if value in {"1", "true", "t", "yes", "y", "on"}:500501 norm = value.strip().lower()502503 if norm in {"1", "true", "t", "yes", "y", "on"}:504 return True505503 elif value in {"0", "false", "f", "no", "n", "off"}:506 if norm in {"0", "false", "f", "no", "n", "off"}:507 return False508509 self.fail(f"{value!r} is not a valid boolean value.", param, ctx)510511 def __repr__(self):512 return "BOOL"
381 unmodified lines
modified:tests/test_options.py+11 added
162 unmodified lines
163 assert not result.exception164 assert result.output == "foo|bar\n"165166167def test_trailing_blanks_boolean_envvar(runner):168 @click.command()169 @click.option("--shout/--no-shout", envvar="SHOUT")170 def cli(shout):171 click.echo(f"shout: {shout!r}")172173 result = runner.invoke(cli, [], env={"SHOUT": " true "})174 assert result.exit_code == 0175 assert result.output == "shout: True\n"176177178def test_multiple_default_help(runner):179 @click.command()180 @click.option("--arg1", multiple=True, default=("foo", "bar"), show_default=True)181 @click.option("--arg2", multiple=True, default=(1, 2), type=int, show_default=True)
451 unmodified lines
modified:CHANGES.rst+2 added
109 unmodified lines
110- Extra context settings (``obj=...``, etc.) are passed on to the111 completion system. :issue:`942`112- Include ``--help`` option in completion. :pr:`1504`113- ``ParameterSource`` is an ``enum.Enum`` subclass. :issue:`1530`114- Boolean type strips surrounding space before converting.115 :issue:`1605`116117118Version 7.1.2119-------------
635 unmodified lines