diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-07-17 16:28:00 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-17 16:28:00 -0400 |
commit | 2df28cbc989c4f43cedd5db0fd5abd1426509567 (patch) | |
tree | e5aa0adc686bc2841b60edc9eefc288752e0d7a6 | |
parent | fa9277157c32b527350eaef74e82515064b4bc5e (diff) | |
parent | b0b825d0cdc0e38b48477719c608a065692f413d (diff) | |
download | cmd2-git-2df28cbc989c4f43cedd5db0fd5abd1426509567.tar.gz |
Merge pull request #959 from python-cmd2/doc_fix
Fixed hook documentation
-rw-r--r-- | cmd2/cmd2.py | 8 | ||||
-rw-r--r-- | docs/features/hooks.rst | 18 |
2 files changed, 13 insertions, 13 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 65047cc8..cdee3523 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -4281,11 +4281,11 @@ class Cmd(cmd.Cmd): 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: diff --git a/docs/features/hooks.rst b/docs/features/hooks.rst index d05e2638..acf9dcc4 100644 --- a/docs/features/hooks.rst +++ b/docs/features/hooks.rst @@ -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 @@ -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 @@ -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) @@ -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) @@ -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) @@ -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) |