File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -635,6 +635,12 @@ def _resolve_parameters(
635635 if name in skip_params :
636636 continue
637637
638+ if param .kind == inspect .Parameter .POSITIONAL_ONLY :
639+ raise TypeError (
640+ f"Parameter { name !r} in { func .__qualname__ } is positional-only, "
641+ "which is not supported by @with_annotated because parameters are passed as keyword arguments."
642+ )
643+
638644 if name in _RESERVED_PARAM_NAMES :
639645 raise ValueError (
640646 f"Parameter name { name !r} in { func .__qualname__ } is reserved by argparse "
Original file line number Diff line number Diff line change @@ -117,6 +117,9 @@ def _func_grouped(
117117) -> None : ...
118118
119119
120+ def _func_positional_only (self , name : str , / ) -> None : ...
121+
122+
120123def _provider (cmd : cmd2 .Cmd ):
121124 return []
122125
@@ -315,6 +318,10 @@ def func(self, subcommand: str) -> None: ...
315318 with pytest .raises (ValueError , match = "subcommand" ):
316319 build_parser_from_function (func )
317320
321+ def test_with_annotated_positional_only_param_raises (self ) -> None :
322+ with pytest .raises (TypeError , match = "positional-only" ):
323+ build_parser_from_function (_func_positional_only )
324+
318325 def test_optional_annotated_outside_raises (self ) -> None :
319326 with pytest .raises (TypeError , match = "Annotated" ):
320327 build_parser_from_function (_func_optional_annotated_outside )
You can’t perform that action at this time.
0 commit comments