summaryrefslogtreecommitdiff
path: root/cmd2
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-07-11 19:46:48 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2018-07-11 19:46:48 -0400
commit6bb7e4c110f8779e550502c251648b7e7af93154 (patch)
tree7fb64dedec5d8226e48c26614e240411301411c6 /cmd2
parente10afbeb6efe7dd806b04bd53eca615bca5d5ffc (diff)
downloadcmd2-git-6bb7e4c110f8779e550502c251648b7e7af93154.tar.gz
Deleted the CmdResult helper class
The CmdResult helper class was deprecated in the previous release. This commit deletes it. - The new CommandResult class is an improved replacement Also: - Deleted the namedtuple_with_two_defaults helper function which is now no longer used
Diffstat (limited to 'cmd2')
-rw-r--r--cmd2/cmd2.py22
-rw-r--r--cmd2/utils.py16
2 files changed, 0 insertions, 38 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 44f3a068..2298f4b9 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -3220,25 +3220,3 @@ class Statekeeper(object):
if self.obj:
for attrib in self.attribs:
setattr(self.obj, attrib, getattr(self, attrib))
-
-
-class CmdResult(utils.namedtuple_with_two_defaults('CmdResult', ['out', 'err', 'war'])):
- """DEPRECATED: Derive a class to store results from a named tuple so we can tweak dunder methods for convenience.
-
- This is provided as a convenience and an example for one possible way for end users to store results in
- the self._last_result attribute of cmd2.Cmd class instances. See the "python_scripting.py" example for how it can
- be used to enable conditional control flow.
-
- Named tuple attributes
- ----------------------
- out - this is intended to store normal output data from the command and can be of any type that makes sense
- err: str - (optional) this is intended to store an error message and it being non-empty indicates there was an error
- Defaults to an empty string
- war: str - (optional) this is intended to store a warning message which isn't quite an error, but of note
- Defaults to an empty string.
-
- NOTE: Named tuples are immutable. So the contents are there for access, not for modification.
- """
- def __bool__(self) -> bool:
- """If err is an empty string, treat the result as a success; otherwise treat it as a failure."""
- return not self.err
diff --git a/cmd2/utils.py b/cmd2/utils.py
index 11d48b78..1f08b416 100644
--- a/cmd2/utils.py
+++ b/cmd2/utils.py
@@ -61,22 +61,6 @@ def namedtuple_with_defaults(typename: str, field_names: Union[str, List[str]],
return T
-def namedtuple_with_two_defaults(typename: str, field_names: Union[str, List[str]],
- default_values: collections.Iterable=('', '')):
- """Wrapper around namedtuple which lets you treat the last value as optional.
-
- :param typename: str - type name for the Named tuple
- :param field_names: List[str] or space-separated string of field names
- :param default_values: (optional) 2-element tuple containing the default values for last 2 parameters in named tuple
- Defaults to an empty string for both of them
- :return: namedtuple type
- """
- T = collections.namedtuple(typename, field_names)
- # noinspection PyUnresolvedReferences
- T.__new__.__defaults__ = default_values
- return T
-
-
def cast(current: Any, new: str) -> Any:
"""Tries to force a new value into the same type as the current when trying to set the value for a parameter.