Skip to content
Myr

Rework method documentation

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

Address: https://github.com/pallets/click/pull/3030/files#r2289127505 https://github.com/pallets/click/pull/3030/files#r2289161176

authored by Kevin Deldycke · committed by Kevin Deldycke · parent f561f18 · Browse files · 3 files+43 added−30 removed
This commit

State

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

Trailers

  • Address:
  • https: //github.com/pallets/click/pull/3030/files#r2289127505
  • https: //github.com/pallets/click/pull/3030/files#r2289161176

Diff stats

3 files+43 added−30 removed

  • tests:+2 added−2 removed
  • other:+41 added−28 removed

3 files+43 added−30 removed

modified:src/click/core.py+41 added-28 removed
2435 unmodified lines
24362437 def handle_parse_result(2438 self, ctx: Context, opts: cabc.Mapping[str, t.Any], args: list[str]2439 ) -> tuple[t.Any, list[str]]:2440 """Process the value produced by the parser from user input."""2440 """Process the value produced by the parser from user input.24412442 Always process the value through the Parameter's :attr:`type`, wherever it2443 comes from.24442445 If the parameter is deprecated, this method warn the user about it. But only if2446 the value has been explicitly set by the user (and as such, is not coming from2447 a default).2448 """2449 with augment_usage_errors(ctx, param=self):2450 value, source = self.consume_value(ctx, opts)24512452 ctx.set_parameter_source(self.name, source) # type: ignore24532446 # Only try to process the value if it is not coming from the defaults.2447 # Defaults set by the users are under their control and so are left2448 # untouched as Python values: these values does not need to be processed.2449 if source not in (ParameterSource.DEFAULT, ParameterSource.DEFAULT_MAP):2450 # If the parameter is deprecated, we want to warn the user about it.2451 # If the value is UNSET there is no need to warn the user of a2452 # parameter that has not been invoked.2453 if self.deprecated and value is not UNSET:2454 extra_message = (2455 f" {self.deprecated}"2456 if isinstance(self.deprecated, str)2457 else ""2458 )2459 message = _(2460 "DeprecationWarning: The {param_type} {name!r} is deprecated."2461 "{extra_message}"2462 ).format(2463 param_type=self.param_type_name,2464 name=self.human_readable_name,2465 extra_message=extra_message,2466 )2467 echo(style(message, fg="red"), err=True)2454 # Display a deprecation warning if necessary.2455 if (2456 self.deprecated2457 and value is not UNSET2458 and source not in (ParameterSource.DEFAULT, ParameterSource.DEFAULT_MAP)2459 ):2460 extra_message = (2461 f" {self.deprecated}" if isinstance(self.deprecated, str) else ""2462 )2463 message = _(2464 "DeprecationWarning: The {param_type} {name!r} is deprecated."2465 "{extra_message}"2466 ).format(2467 param_type=self.param_type_name,2468 name=self.human_readable_name,2469 extra_message=extra_message,2470 )2471 echo(style(message, fg="red"), err=True)24722473 # Process the value through the parameter's type.2474 try:2475 value = self.process_value(ctx, value)2476 except Exception:2477 if not ctx.resilient_parsing:2478 raise24742475 # Ignore values that we have a hard time processing.2479 # In resilient parsing mode, we do not want to fail the command if the2480 # value is incompatible with the parameter type, so we reset the value2481 # to UNSET, which will be interpreted as a missing value.2482 value = UNSET24832478 if self.expose_value and self.name not in ctx.params:2484 # Add parameter's value to the context.2485 if (2486 self.expose_value2487 # We skip adding the value if it was previously set by another parameter2488 # targeting the same variable name. This prevents parameters competing for2489 # the same name to override each other.2490 and self.name not in ctx.params2491 ):2492 # Click is logically enforcing that the name is None if the parameter is2480 # not exposed. We still assert it here to please the type checker.2493 # not to be exposed. We still assert it here to please the type checker.2494 assert self.name is not None, (2495 f"{self!r} parameter's name should not be None when exposing value."2496 )2484 # Normalize unset values to None, as we're about to pass them to the2497 # Normalize UNSET values to None, as we're about to pass them to the2498 # command function and move them to the pure-Python realm of user-written2499 # code.2500 ctx.params[self.name] = value if value is not UNSET else None2501
783 unmodified lines
modified:tests/test_basic.py+1 added-1 removed
284 unmodified lines
285 (True, [], "True"),286 ("upper", [], "upper"),287 ),288)289def test_flag_value(runner, default, args, expect):289def test_flag_value_dual_options(runner, default, args, expect):290 @click.command()291 @click.option("--upper", "transformation", flag_value="upper", default=default)292 @click.option("--lower", "transformation", flag_value="lower")293 def cli(transformation):
411 unmodified lines
modified:tests/test_options.py+1 added-1 removed
1370 unmodified lines
1371 (None, ["--js"], "js"),1372 (None, ["--xml"], "xml"),1373 ],1374)1375def test_flag_value_callback(runner, default, args, expected):1375def test_flag_value_dual_callback(runner, default, args, expected):1376 """1377 Reproduction of the issue reported in1378 https://github.com/pallets/click/pull/3030#discussion_r22715718191379 """
560 unmodified lines