diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-03-18 22:47:24 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-18 22:47:24 -0400 |
commit | 57dd827963491439e40eb5dfe20811c14ea757ff (patch) | |
tree | 9503d37d813a83a4c991d8ff8b2ed92e4a97e4ce /cmd2/parsing.py | |
parent | 83a28727d012ab067d18d89d3b1ce6410459f67b (diff) | |
parent | 4523bc6a9fc36ff879b6767dcd23923aa40c4c47 (diff) | |
download | cmd2-git-57dd827963491439e40eb5dfe20811c14ea757ff.tar.gz |
Merge pull request #648 from python-cmd2/attributes
Converted class attributes to instance attributes
Diffstat (limited to 'cmd2/parsing.py')
-rw-r--r-- | cmd2/parsing.py | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/cmd2/parsing.py b/cmd2/parsing.py index 514f5faf..2dc698b0 100644 --- a/cmd2/parsing.py +++ b/cmd2/parsing.py @@ -5,7 +5,7 @@ import os import re import shlex -from typing import Dict, List, Tuple, Union +from typing import Dict, Iterable, List, Optional, Tuple, Union import attr @@ -242,31 +242,42 @@ class StatementParser: Shortcuts is a list of tuples with each tuple containing the shortcut and the expansion. """ - def __init__( - self, - allow_redirection: bool = True, - terminators: List[str] = None, - multiline_commands: List[str] = None, - aliases: Dict[str, str] = None, - shortcuts: List[Tuple[str, str]] = None, - ): + def __init__(self, + allow_redirection: bool = True, + terminators: Optional[Iterable[str]] = None, + multiline_commands: Optional[Iterable[str]] = None, + aliases: Optional[Dict[str, str]] = None, + shortcuts: Optional[Iterable[Tuple[str, str]]] = None) -> None: + """Initialize an instance of StatementParser. + + The following will get converted to an immutable tuple before storing internally: + * terminators + * multiline commands + * shortcuts + + :param allow_redirection: (optional) should redirection and pipes be allowed? + :param terminators: (optional) iterable containing strings which should terminate multiline commands + :param multiline_commands: (optional) iterable containing the names of commands that accept multiline input + :param aliases: (optional) dictionary contaiing aliases + :param shortcuts (optional) an iterable of tuples with each tuple containing the shortcut and the expansion + """ self.allow_redirection = allow_redirection if terminators is None: - self.terminators = [constants.MULTILINE_TERMINATOR] + self.terminators = (constants.MULTILINE_TERMINATOR,) else: - self.terminators = terminators + self.terminators = tuple(terminators) if multiline_commands is None: - self.multiline_commands = [] + self.multiline_commands = tuple() else: - self.multiline_commands = multiline_commands + self.multiline_commands = tuple(multiline_commands) if aliases is None: - self.aliases = {} + self.aliases = dict() else: self.aliases = aliases if shortcuts is None: - self.shortcuts = [] + self.shortcuts = tuple() else: - self.shortcuts = shortcuts + self.shortcuts = tuple(shortcuts) # commands have to be a word, so make a regular expression # that matches the first word in the line. This regex has three |