diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-07-09 23:18:28 -0400 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-07-09 23:18:28 -0400 |
commit | 766f8f7b02f771d7cd4ca812c1f0ebfe76e5faf8 (patch) | |
tree | a37ba6637c53adf45dbf0f7f4a345997f7a269cd /cmd2 | |
parent | 60c18dfcc371713cebb22cc47aec173bd95687ce (diff) | |
download | cmd2-git-766f8f7b02f771d7cd4ca812c1f0ebfe76e5faf8.tar.gz |
Fixed a couple type hints and minor pep8-style formatting issues
Diffstat (limited to 'cmd2')
-rw-r--r-- | cmd2/cmd2.py | 16 | ||||
-rw-r--r-- | cmd2/parsing.py | 35 | ||||
-rw-r--r-- | cmd2/plugin.py | 12 |
3 files changed, 33 insertions, 30 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 524d1d8e..8bdcf083 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -1756,7 +1756,7 @@ class Cmd(cmd.Cmd): finally: return self._run_cmdfinalization_hooks(stop, statement) - def _run_cmdfinalization_hooks(self, stop: bool, statement: Statement) -> bool: + def _run_cmdfinalization_hooks(self, stop: bool, statement: Optional[Statement]) -> bool: """Run the command finalization hooks""" try: data = plugin.CommandFinalizationData(stop, statement) @@ -3179,7 +3179,7 @@ Script should contain one command per line, just like command would be typed in cls._validate_callable_param_count(func, 0) # make sure there is no return notation signature = inspect.signature(func) - if signature.return_annotation != None: + if signature.return_annotation is not None: raise TypeError("{} must declare return a return type of 'None'".format( func.__name__, )) @@ -3259,20 +3259,18 @@ Script should contain one command per line, just like command would be typed in 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 " + "'cmd2.plugin.CommandFinalizationData'".format(func.__name__)) if signature.return_annotation != plugin.CommandFinalizationData: - raise TypeError("{} must declare return a return type of 'cmd2.plugin.CommandFinalizationData'".format( - func.__name__ - )) - pass + raise TypeError("{} must declare return a return type of " + "'cmd2.plugin.CommandFinalizationData'".format(func.__name__)) def register_cmdfinalization_hook(self, func: Callable): """Register a hook to be called after a command is completed, whether it completes successfully or not.""" self._validate_cmdfinalization_callable(func) self._cmdfinalization_hooks.append(func) + class History(list): """ A list of HistoryItems that knows how to respond to user requests. """ diff --git a/cmd2/parsing.py b/cmd2/parsing.py index aa913187..f7000ce0 100644 --- a/cmd2/parsing.py +++ b/cmd2/parsing.py @@ -68,7 +68,7 @@ class Statement(str): suffix: str = None, pipe_to: str = None, output: str = None, - output_to:str = None + output_to: str = None ): """Create a new instance of Statement @@ -113,6 +113,7 @@ class Statement(str): """Statement instances should feel immutable; raise ValueError""" raise ValueError + class StatementParser: """Parse raw text into command components. @@ -124,7 +125,7 @@ class StatementParser: terminators: List[str] = None, multiline_commands: List[str] = None, aliases: Dict[str, str] = None, - shortcuts: Dict[str, str] = None, + shortcuts: List[Tuple[str, str]] = None, ): self.allow_redirection = allow_redirection if terminators is None: @@ -391,17 +392,17 @@ class StatementParser: # string representation of args must be an empty string instead of # None for compatibility with standard library cmd statement = Statement('' if args is None else args, - raw=line, - command=command, - args=args, - argv=list(map(lambda x: utils.strip_quotes(x), argv)), - multiline_command=multiline_command, - terminator=terminator, - suffix=suffix, - pipe_to=pipe_to, - output=output, - output_to=output_to, - ) + raw=line, + command=command, + args=args, + argv=list(map(lambda x: utils.strip_quotes(x), argv)), + multiline_command=multiline_command, + terminator=terminator, + suffix=suffix, + pipe_to=pipe_to, + output=output, + output_to=output_to, + ) return statement def parse_command_only(self, rawinput: str) -> Statement: @@ -452,10 +453,10 @@ class StatementParser: # string representation of args must be an empty string instead of # None for compatibility with standard library cmd statement = Statement('' if args is None else args, - raw=rawinput, - command=command, - args=args, - ) + raw=rawinput, + command=command, + args=args, + ) return statement def _expand(self, line: str) -> str: diff --git a/cmd2/plugin.py b/cmd2/plugin.py index 5c68dfb9..dc9ec297 100644 --- a/cmd2/plugin.py +++ b/cmd2/plugin.py @@ -3,21 +3,25 @@ """Classes for the cmd2 plugin system""" import attr + @attr.s -class PostparsingData(): +class PostparsingData: stop = attr.ib() statement = attr.ib() + @attr.s -class PrecommandData(): +class PrecommandData: statement = attr.ib() + @attr.s -class PostcommandData(): +class PostcommandData: stop = attr.ib() statement = attr.ib() + @attr.s -class CommandFinalizationData(): +class CommandFinalizationData: stop = attr.ib() statement = attr.ib() |