diff --git a/CHANGELOG.md b/CHANGELOG.md index 54263029..3104ccee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,11 @@ * Added `RawDescriptionCmd2HelpFormatter`, `RawTextCmd2HelpFormatter`, `ArgumentDefaultsCmd2HelpFormatter`, and `MetavarTypeCmd2HelpFormatter` and they all use `rich-argparse`. +## 2.5.5 (November 13, 2024) +* 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 7661b0ba..d8b3f7ad 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -3910,11 +3910,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 1cac0a54..cee30b15 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -176,17 +176,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) @@ -203,7 +200,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: