@@ -2307,6 +2307,41 @@ def test_command_set_completion(self, cmdset_app) -> None:
23072307# ---------------------------------------------------------------------------
23082308
23092309
2310+ def test_subcommand_handler_rejects_keyword_arguments () -> None :
2311+ """The internal subcommand adapter only accepts the owner and parsed namespace positionally."""
2312+
2313+ @with_annotated (subcommand_to = "root" )
2314+ def root_child (self ) -> None :
2315+ pass
2316+
2317+ with pytest .raises (TypeError , match = "do not accept keyword arguments" ):
2318+ root_child (object (), argparse .Namespace (), unexpected = True )
2319+
2320+
2321+ def test_subcommand_handler_requires_namespace () -> None :
2322+ """The internal subcommand adapter rejects calls without a parsed namespace."""
2323+
2324+ @with_annotated (subcommand_to = "root" )
2325+ def root_child (self ) -> None :
2326+ pass
2327+
2328+ with pytest .raises (TypeError , match = r"parsed argparse.Namespace" ):
2329+ root_child (object (), object ())
2330+
2331+
2332+ def test_subcommand_handler_rejects_invalid_return_value () -> None :
2333+ """The internal subcommand adapter enforces the command return contract."""
2334+
2335+ invalid_result : Any = object ()
2336+
2337+ @with_annotated (subcommand_to = "root" )
2338+ def root_child (self ) -> bool | None :
2339+ return invalid_result
2340+
2341+ with pytest .raises (TypeError , match = "must return bool or None" ):
2342+ root_child (object (), argparse .Namespace ())
2343+
2344+
23102345class _IntegrationApp (cmd2 .Cmd ):
23112346 def __init__ (self ) -> None :
23122347 super ().__init__ ()
0 commit comments