From fe4d79085391f2f461a5bfe50836c5711dc15377 Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Wed, 13 Nov 2024 00:39:11 -0500 Subject: [PATCH] Fixed issue where set command was not always printing a settable's current value. --- CHANGELOG.md | 5 +++++ cmd2/cmd2.py | 4 ++-- cmd2/utils.py | 14 +++++--------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 074eb33d..30374004 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.5.5 (TBD) +* Bug Fixes + * Fixed type hints for passing a class method to `with_argparser` and `as_subcommand_to`. + * Fixed issue where `set` command was not always printing a settable's current value. + ## 2.5.4 (November 6, 2024) * Bug Fixes * Fixed `ZeroDivisionError` in `async_alert()` when `shutil.get_terminal_size().columns` is 0. diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index d3a1f159..e9878b23 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -4226,11 +4226,11 @@ def do_set(self, args: argparse.Namespace) -> None: # Try to update the settable's value try: orig_value = settable.get_value() - new_value = settable.set_value(utils.strip_quotes(args.value)) + settable.set_value(utils.strip_quotes(args.value)) except Exception as ex: self.perror(f"Error setting {args.param}: {ex}") else: - self.poutput(f"{args.param} - was: {orig_value!r}\nnow: {new_value!r}") + self.poutput(f"{args.param} - was: {orig_value!r}\nnow: {settable.get_value()!r}") self.last_result = True return diff --git a/cmd2/utils.py b/cmd2/utils.py index bd4164ab..1bb435fd 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -178,17 +178,14 @@ def get_bool_choices(_) -> List[str]: # type: ignore[no-untyped-def] self.completer = completer def get_value(self) -> Any: - """ - Get the value of the settable attribute - :return: - """ + """Get the value of the settable attribute.""" return getattr(self.settable_obj, self.settable_attrib_name) - def set_value(self, value: Any) -> Any: + def set_value(self, value: Any) -> None: """ - Set the settable attribute on the specified destination object - :param value: New value to set - :return: New value that the attribute was set to + Set the settable attribute on the specified destination object. + + :param value: new value to set """ # Run the value through its type function to handle any conversion or validation new_value = self.val_type(value) @@ -205,7 +202,6 @@ def set_value(self, value: Any) -> Any: # Check if we need to call an onchange callback if orig_value != new_value and self.onchange_cb: self.onchange_cb(self.name, orig_value, new_value) - return new_value def is_text_file(file_path: str) -> bool: