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

Method _validate_postparsing_callable

cmd2/cmd2.py:5842–5852  ·  view source on GitHub ↗

Check parameter and return types for postparsing hooks.

(cls, func: Callable[[plugin.PostparsingData], plugin.PostparsingData])

Source from the content-addressed store, hash-verified

5840
5841 @classmethod
5842 def _validate_postparsing_callable(cls, func: Callable[[plugin.PostparsingData], plugin.PostparsingData]) -> None:
5843 """Check parameter and return types for postparsing hooks."""
5844 cls._validate_callable_param_count(cast(Callable[..., Any], func), 1)
5845 type_hints, ret_ann = get_types(func)
5846 if not type_hints:
5847 raise TypeError(f"{func.__name__} parameter is missing a type hint, expected: 'cmd2.plugin.PostparsingData'")
5848 par_ann = next(iter(type_hints.values()))
5849 if par_ann != plugin.PostparsingData:
5850 raise TypeError(f"{func.__name__} must have one parameter declared with type 'cmd2.plugin.PostparsingData'")
5851 if ret_ann != plugin.PostparsingData:
5852 raise TypeError(f"{func.__name__} must declare return a return type of 'cmd2.plugin.PostparsingData'")
5853
5854 def register_postparsing_hook(self, func: Callable[[plugin.PostparsingData], plugin.PostparsingData]) -> None:
5855 """Register a function to be called after parsing user input but before running the command."""

Callers 1

Calls 2

get_typesFunction · 0.85

Tested by

no test coverage detected