@@ -309,6 +309,7 @@ def do_build(self, target: str, common: CommonArgs):
309309from .exceptions import Cmd2ArgparseError
310310from .rich_utils import Cmd2HelpFormatter , HelpContent
311311from .types import (
312+ BoundCommandFunc ,
312313 CmdOrSetT ,
313314 UnboundChoicesProvider ,
314315 UnboundCompleter ,
@@ -318,20 +319,6 @@ def do_build(self, target: str, common: CommonArgs):
318319_NargsValue = int | str | tuple [int ] | tuple [int , int ] | tuple [int , float ]
319320
320321
321- class _CommandFunc (Protocol ):
322- """The command-function interface required by the annotation machinery.
323-
324- The parser builders only depend on a command's name metadata and its
325- boolean command result; they never depend on whether the function is
326- bound or unbound, nor on the types of its parsed arguments.
327- """
328-
329- __name__ : str
330- __qualname__ : str
331-
332- def __call__ (self , * args : Any , ** kwargs : Any ) -> bool | None : ...
333-
334-
335322class Cmd2ParserKwargs (TypedDict , total = False ):
336323 """Forwarded ctor kwargs for [`Cmd2ArgumentParser`][cmd2.argparse_utils.Cmd2ArgumentParser] (PEP 692 ``Unpack``).
337324
@@ -2132,7 +2119,7 @@ def _link_mutex_group_membership(
21322119 by_name [name ].mutex_group_indices .append (index )
21332120
21342121
2135- def _resolve_func_hints (func : _CommandFunc , * , skip_params : frozenset [str ] = _SKIP_PARAMS ) -> dict [str , Any ]:
2122+ def _resolve_func_hints (func : BoundCommandFunc , * , skip_params : frozenset [str ] = _SKIP_PARAMS ) -> dict [str , Any ]:
21362123 """Resolve the type hints for the parameters that become arguments.
21372124
21382125 The bound first parameter (self/cls), the injected ``skip_params``, and the ``return`` annotation
@@ -2310,7 +2297,7 @@ def _block_field_dest(spec: _BlockSpec, field_name: str) -> str:
23102297 return _shared_field_dest (spec .dc_type , field_name ) if spec .shared else field_name
23112298
23122299
2313- def _dataclass_blocks (func : _CommandFunc , * , skip_params : frozenset [str ] = _SKIP_PARAMS ) -> dict [str , _BlockSpec ]:
2300+ def _dataclass_blocks (func : BoundCommandFunc , * , skip_params : frozenset [str ] = _SKIP_PARAMS ) -> dict [str , _BlockSpec ]:
23142301 """Map each dataclass-block parameter name to its :class:`_BlockSpec`.
23152302
23162303 Used by the runtime handler to reconstruct the dataclass instance from the parsed namespace. A
@@ -2334,7 +2321,7 @@ def _dataclass_blocks(func: _CommandFunc, *, skip_params: frozenset[str] = _SKIP
23342321
23352322
23362323def _lazy_block_resolver (
2337- func : _CommandFunc ,
2324+ func : BoundCommandFunc ,
23382325 * ,
23392326 base_accepted : set [str ],
23402327 skip_params : frozenset [str ],
@@ -2391,7 +2378,7 @@ def _reconstruct_dataclass_blocks(func_kwargs: dict[str, Any], blocks: dict[str,
23912378
23922379
23932380def _resolve_parameters (
2394- func : _CommandFunc ,
2381+ func : BoundCommandFunc ,
23952382 * ,
23962383 skip_params : frozenset [str ] = _SKIP_PARAMS ,
23972384 base_command : bool = False ,
@@ -2735,7 +2722,7 @@ def _docstring_first_paragraph(doc: str | None) -> str | None:
27352722
27362723
27372724def build_parser_from_function (
2738- func : _CommandFunc ,
2725+ func : BoundCommandFunc ,
27392726 * ,
27402727 skip_params : frozenset [str ] = _SKIP_PARAMS ,
27412728 groups : tuple [Group , ...] | None = None ,
@@ -2810,7 +2797,7 @@ def build_parser_from_function(
28102797 return parser
28112798
28122799
2813- def _derive_subcommand_name (func : _CommandFunc , subcommand_to : str ) -> str :
2800+ def _derive_subcommand_name (func : BoundCommandFunc , subcommand_to : str ) -> str :
28142801 """Derive the subcommand name from the function name and validate the naming convention.
28152802
28162803 ``subcommand_to='team member'`` + ``func.__name__='team_member_add'`` -> ``'add'``.
@@ -2846,7 +2833,7 @@ class _ParserBuildOptions:
28462833
28472834
28482835def _make_parser_builder (
2849- func : _CommandFunc ,
2836+ func : BoundCommandFunc ,
28502837 * ,
28512838 skip_params : frozenset [str ],
28522839 base_command : bool ,
@@ -2885,12 +2872,12 @@ def parser_builder() -> Cmd2ArgumentParser:
28852872
28862873
28872874def _build_subcommand_handler (
2888- func : _CommandFunc ,
2875+ func : BoundCommandFunc ,
28892876 subcommand_to : str ,
28902877 * ,
28912878 base_command : bool = False ,
28922879 options : _ParserBuildOptions ,
2893- ) -> tuple [_CommandFunc , str , Callable [[], Cmd2ArgumentParser ]]:
2880+ ) -> tuple [BoundCommandFunc , str , Callable [[], Cmd2ArgumentParser ]]:
28942881 """Build a subcommand's parser and a handler that unpacks the Namespace into typed kwargs.
28952882
28962883 :param func: the subcommand handler function
@@ -2936,7 +2923,7 @@ def handler(self_arg: Any, ns: Any) -> Any:
29362923_CommandParams = ParamSpec ("_CommandParams" )
29372924
29382925
2939- class _AnnotatedCommand (_CommandFunc , Protocol [_CommandParams ]):
2926+ class _AnnotatedCommand (BoundCommandFunc , Protocol [_CommandParams ]):
29402927 """A callable command method with the metadata used by ``with_annotated``."""
29412928
29422929 def __call__ (self , * args : _CommandParams .args , ** kwargs : _CommandParams .kwargs ) -> bool | None : ...
0 commit comments