MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / _prepare_callable_params

Method _prepare_callable_params

cmd2/argparse_completer.py:722–748  ·  view source on GitHub ↗

Resolve the instance and arguments required to call a choices/completer function.

(
        self,
        to_call: UnboundChoicesProvider[CmdOrSetT] | UnboundCompleter[CmdOrSetT],
        arg_state: _ArgumentState,
        text: str,
        consumed_arg_values: dict[str, list[str]],
        cmd_set: CommandSet[Any] | None,
    )

Source from the content-addressed store, hash-verified

720 ]
721
722 def _prepare_callable_params(
723 self,
724 to_call: UnboundChoicesProvider[CmdOrSetT] | UnboundCompleter[CmdOrSetT],
725 arg_state: _ArgumentState,
726 text: str,
727 consumed_arg_values: dict[str, list[str]],
728 cmd_set: CommandSet[Any] | None,
729 ) -> tuple[list[Any], dict[str, Any]]:
730 """Resolve the instance and arguments required to call a choices/completer function."""
731 args: list[Any] = []
732 kwargs: dict[str, Any] = {}
733
734 # Resolve the 'self' instance for the method
735 self_arg = self._cmd2_app._resolve_func_self(to_call, cmd_set)
736 if self_arg is None:
737 raise CompletionError("Could not find CommandSet instance matching defining type")
738
739 args.append(self_arg)
740
741 # Check if the function expects 'arg_tokens'
742 to_call_params = inspect.signature(to_call).parameters
743 if ARG_TOKENS in to_call_params:
744 arg_tokens = {**self._parent_tokens, **consumed_arg_values}
745 arg_tokens.setdefault(arg_state.action.dest, []).append(text)
746 kwargs[ARG_TOKENS] = arg_tokens
747
748 return args, kwargs
749
750 def _complete_arg(
751 self,

Callers 1

_complete_argMethod · 0.95

Calls 3

CompletionErrorClass · 0.85
_resolve_func_selfMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected