Process the value produced by the parser from user input. Always process the value through the Parameter's :attr:`type`, wherever it comes from. If the parameter is deprecated, this method warn the user about it. But only if the value has been explicitly set by the
(
self, ctx: Context, opts: cabc.Mapping[str, t.Any], args: list[str]
)
| 2661 | return rv |
| 2662 | |
| 2663 | def handle_parse_result( |
| 2664 | self, ctx: Context, opts: cabc.Mapping[str, t.Any], args: list[str] |
| 2665 | ) -> tuple[t.Any, list[str]]: |
| 2666 | """Process the value produced by the parser from user input. |
| 2667 | |
| 2668 | Always process the value through the Parameter's :attr:`type`, wherever it |
| 2669 | comes from. |
| 2670 | |
| 2671 | If the parameter is deprecated, this method warn the user about it. But only if |
| 2672 | the value has been explicitly set by the user (and as such, is not coming from |
| 2673 | a default). |
| 2674 | |
| 2675 | :meta private: |
| 2676 | """ |
| 2677 | # Capture the slot's existing state before we mutate |
| 2678 | # ``_parameter_source`` so the write decision below can compare our |
| 2679 | # incoming source against the source of the option that already wrote |
| 2680 | # the slot (if any). |
| 2681 | existing_value = ctx.params.get(self.name, UNSET) |
| 2682 | existing_source = ctx.get_parameter_source(self.name) |
| 2683 | existing_default_explicit = ctx._param_default_explicit.get(self.name, False) |
| 2684 | |
| 2685 | with augment_usage_errors(ctx, param=self): |
| 2686 | value, source = self.consume_value(ctx, opts) |
| 2687 | |
| 2688 | # Record the source before processing so eager callbacks and type |
| 2689 | # conversion can inspect it. Restored after arbitration if this |
| 2690 | # option loses a feature-switch group. |
| 2691 | ctx.set_parameter_source(self.name, source) |
| 2692 | |
| 2693 | # Display a deprecation warning if necessary. |
| 2694 | if ( |
| 2695 | self.deprecated |
| 2696 | and value is not UNSET |
| 2697 | and source < ParameterSource.DEFAULT_MAP |
| 2698 | ): |
| 2699 | message = _( |
| 2700 | "DeprecationWarning: The {param_type} {name!r} is deprecated." |
| 2701 | "{extra_message}" |
| 2702 | ).format( |
| 2703 | param_type=self.param_type_name, |
| 2704 | name=self.human_readable_name, |
| 2705 | extra_message=_format_deprecated_suffix(self.deprecated), |
| 2706 | ) |
| 2707 | echo(style(message, fg="red"), err=True) |
| 2708 | |
| 2709 | # Process the value through the parameter's type. |
| 2710 | try: |
| 2711 | value = self.process_value(ctx, value) |
| 2712 | except Exception: |
| 2713 | if not ctx.resilient_parsing: |
| 2714 | raise |
| 2715 | # In resilient parsing mode, we do not want to fail the command if the |
| 2716 | # value is incompatible with the parameter type, so we reset the value |
| 2717 | # to UNSET, which will be interpreted as a missing value. |
| 2718 | value = UNSET |
| 2719 | |
| 2720 | # Arbitrate the slot when several parameters target the same variable |
no test coverage detected