Skip to content
Myr

Merge branch '8.0.x'

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 · parents 655918a, 96146c9 · Browse files · 3 files+75 added−19 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+75 added−19 removed

  • tests:+49 added−3 removed
  • other:+26 added−16 removed

3 files+75 added−19 removed

modified:src/click/core.py+19 added-15 removed
2190 unmodified lines
2191 :param ctx: Current context.2192 :param call: If the default is a callable, call it. Disable to2193 return the callable instead.21942195 .. versionchanged:: 8.0.22196 Type casting is no longer performed when getting a default.21972198 .. versionchanged:: 8.0.12199 Type casting can fail in resilient parsing mode. Invalid2200 defaults will not prevent showing help text.2201
7 unmodified lines
22092210 if value is None:2211 value = self.default22122210 if callable(value):2211 if not call:2212 # Don't type cast the callable.2213 return value22142213 if call and callable(value):2214 value = value()22152217 try:2218 return self.type_cast_value(ctx, value)2219 except BadParameter:2220 if ctx.resilient_parsing:2221 return value2216 return value22172223 raise22242218 def add_to_parser(self, parser: OptionParser, ctx: Context) -> None:2219 raise NotImplementedError()22202221 def consume_value(
75 unmodified lines
22972298 return False22992300 def process_value(self, ctx: Context, value: t.Any) -> t.Any:2308 if value is not None:2309 value = self.type_cast_value(ctx, value)2301 value = self.type_cast_value(ctx, value)23022303 if self.required and self.value_is_missing(value):2304 raise MissingParameter(ctx=ctx, param=self)2305
432 unmodified lines
27382739 if default_string:2740 extra.append(_("default: {default}").format(default=default_string))27412750 if isinstance(self.type, types._NumberRangeBase):2742 if (2743 isinstance(self.type, types._NumberRangeBase)2744 # skip count with default range type2745 and not (self.count and self.type.min == 0 and self.type.max is None)2746 ):2747 range_str = self.type._describe_range()27482749 if range_str:2750 extra.append(range_str)
108 unmodified lines
2859 else:2860 value = self.flag_value2861 source = ParameterSource.COMMANDLINE28622863 elif (2864 self.multiple2865 and value is not None2866 and any(v is _flag_needs_value for v in value)2867 ):2868 value = [self.flag_value if v is _flag_needs_value else v for v in value]2869 source = ParameterSource.COMMANDLINE28702871 # The value wasn't set, or used the param's default, prompt if2872 # prompting is enabled.2873 elif (2874 source in {None, ParameterSource.DEFAULT}
84 unmodified lines
modified:tests/test_options.py+49 added-3 removed
250 unmodified lines
251 assert opt.multiple252 assert isinstance(opt.type, click.Tuple)253 assert opt.type.types == [click.INT, click.STRING]254 ctx = click.Context(click.Command("test"))255 assert opt.get_default(ctx) == ((1, "a"),)255 assert opt.type_cast_value(ctx, opt.get_default(ctx)) == ((1, "a"),)256257258def test_parse_multiple_default_composite_type(runner):259 @click.command()
53 unmodified lines
313 (click.IntRange(1), "x>=1"),314 (click.IntRange(max=32), "x<=32"),315 ],316)317def test_intrange_default_help_text(runner, type, expect):318 option = click.Option(["--count"], type=type, show_default=True, default=2)317def test_intrange_default_help_text(type, expect):318 option = click.Option(["--num"], type=type, show_default=True, default=2)319 context = click.Context(click.Command("test"))320 result = option.get_help_record(context)[1]321 assert expect in result322323324def test_count_default_type_help():325 """A count option with the default type should not show >=0 in help."""326 option = click.Option(["--count"], count=True, help="some words")327 context = click.Context(click.Command("test"))328 result = option.get_help_record(context)[1]329 assert result == "some words"330331332def test_file_type_help_default():333 """The default for a File type is a filename string. The string334 should be displayed in help, not an open file object.335336 Type casting is only applied to defaults in processing, not when337 getting the default value.338 """339 option = click.Option(340 ["--in"], type=click.File(), default=__file__, show_default=True341 )342 context = click.Context(click.Command("test"))343 result = option.get_help_record(context)[1]344 assert __file__ in result345346347def test_toupper_envvar_prefix(runner):348 @click.command()349 @click.option("--arg")350 def cmd(arg):
461 unmodified lines
812 result = runner.invoke(cli, args, standalone_mode=False, catch_exceptions=False)813 assert result.return_value == expect814815816def test_multiple_option_with_optional_value(runner):817 cli = click.Command(818 "cli",819 params=[820 click.Option(["-f"], is_flag=False, flag_value="flag", multiple=True),821 click.Option(["-a"]),822 click.Argument(["b"], nargs=-1),823 ],824 callback=lambda **kwargs: kwargs,825 )826 result = runner.invoke(827 cli,828 ["-f", "-f", "other", "-f", "-a", "1", "a", "b"],829 standalone_mode=False,830 catch_exceptions=False,831 )832 assert result.return_value == {833 "f": ("flag", "other", "flag"),834 "a": "1",835 "b": ("a", "b"),836 }837838839def test_type_from_flag_value():840 param = click.Option(["-a", "x"], default=True, flag_value=4)841 assert param.type is click.INT842 param = click.Option(["-b", "x"], flag_value=8)
20 unmodified lines
modified:CHANGES.rst+7 added-1 removed
10 unmodified lines
1112Version 8.0.213-------------1415Unreleased15Released 2021-10-081617- ``is_bool_flag`` is not set to ``True`` if ``is_flag`` is ``False``.18 :issue:`1925`19- Bash version detection is locale independent. :issue:`1940`
8 unmodified lines
28- Fix type annotation for ``type`` argument in ``prompt`` function.29 :issue:`2062`30- Fix overline and italic styles, which were incorrectly added when31 adding underline. :pr:`2058`32- An option with ``count=True`` will not show "[x>=0]" in help text.33 :issue:`2072`34- Default values are not cast to the parameter type twice during35 processing. :issue:`2085`36- Options with ``multiple`` and ``flag_value`` use the flag value37 instead of leaving an internal placeholder. :issue:`2001`383940Version 8.0.141-------------
889 unmodified lines