Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmd2/cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4281,11 +4281,11 @@ def _validate_cmdfinalization_callable(cls, func: Callable[[plugin.CommandFinali
signature = inspect.signature(func)
_, param = list(signature.parameters.items())[0]
if param.annotation != plugin.CommandFinalizationData:
raise TypeError("{} must have one parameter declared with type "
"'cmd2.plugin.CommandFinalizationData'".format(func.__name__))
raise TypeError("{} must have one parameter declared with type {}".format(func.__name__,
plugin.CommandFinalizationData))
if signature.return_annotation != plugin.CommandFinalizationData:
raise TypeError("{} must declare return a return type of "
"'cmd2.plugin.CommandFinalizationData'".format(func.__name__))
raise TypeError("{} must declare return a return type of {}".format(func.__name__,
plugin.CommandFinalizationData))

def register_cmdfinalization_hook(self, func: Callable[[plugin.CommandFinalizationData],
plugin.CommandFinalizationData]) -> None:
Expand Down
18 changes: 9 additions & 9 deletions docs/features/hooks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ You can also register methods to be called at the beginning of the command
loop::

class App(cmd2.Cmd):
def __init__(self, *args, *kwargs):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.register_preloop_hook(self.myhookmethod)

def myhookmethod(self):
def myhookmethod(self) -> None:
self.poutput("before the loop begins")

To retain backwards compatibility with ``cmd.Cmd``, after all registered
Expand All @@ -41,12 +41,12 @@ A similar approach allows you to register functions to be called after the
command loop has finished::

class App(cmd2.Cmd):
def __init__(self, *args, *kwargs):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.register_postloop_hook(self.myhookmethod)

def myhookmethod(self):
self.poutput("before the loop begins")
def myhookmethod(self) -> None:
self.poutput("after the loop ends")

To retain backwards compatibility with ``cmd.Cmd``, after all registered
postloop hooks have been called, the :meth:`~cmd2.Cmd.postloop` method is
Expand Down Expand Up @@ -147,7 +147,7 @@ timer for command execution been started.
To define and register a postparsing hook, do the following::

class App(cmd2.Cmd):
def __init__(self, *args, *kwargs):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.register_postparsing_hook(self.myhookmethod)

Expand Down Expand Up @@ -215,7 +215,7 @@ Once output is redirected and the timer started, all the hooks registered with
:meth:`~cmd2.Cmd.register_precmd_hook` are called. Here's how to do it::

class App(cmd2.Cmd):
def __init__(self, *args, *kwargs):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.register_precmd_hook(self.myhookmethod)

Expand Down Expand Up @@ -254,7 +254,7 @@ timer is still running.
Here's how to define and register a postcommand hook::

class App(cmd2.Cmd):
def __init__(self, *args, *kwargs):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.register_postcmd_hook(self.myhookmethod)

Expand Down Expand Up @@ -306,7 +306,7 @@ or the command method raise an exception. Here's how to create and register a
command finalization hook::

class App(cmd2.Cmd):
def __init__(self, *args, *kwargs):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.register_cmdfinalization_hook(self.myhookmethod)

Expand Down