Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions cmd2/cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1240,20 +1240,20 @@ def always_prefix_settables(self) -> bool:
return self._always_prefix_settables

@always_prefix_settables.setter
def always_prefix_settables(self, new_value: bool) -> None:
def always_prefix_settables(self, value: bool) -> None:
"""Set whether CommandSet settable values should always be prefixed.

:param new_value: True if CommandSet settable values should always be prefixed. False if not.
:param value: True if CommandSet settable values should always be prefixed. False if not.
:raises ValueError: If a registered CommandSet does not have a defined prefix
"""
if not self._always_prefix_settables and new_value:
if not self._always_prefix_settables and value:
for cmd_set in self._installed_command_sets:
if not cmd_set.settable_prefix:
raise ValueError(
f"Cannot force settable prefixes. CommandSet {cmd_set.__class__.__name__} does "
f"not have a settable prefix defined."
)
self._always_prefix_settables = new_value
self._always_prefix_settables = value

@property
def settables(self) -> Mapping[str, Settable]:
Expand Down Expand Up @@ -1357,14 +1357,20 @@ def allow_style(self) -> ru.AllowStyle:
return ru.ALLOW_STYLE

@allow_style.setter
def allow_style(self, new_val: ru.AllowStyle) -> None:
def allow_style(self, value: ru.AllowStyle) -> None:
"""Setter property needed to support do_set when it updates allow_style."""
ru.ALLOW_STYLE = new_val
ru.ALLOW_STYLE = value

@property
def traceback_show_locals(self) -> bool:
"""Property needed to support do_set when it reads traceback_show_locals."""
return cast(bool, self.traceback_kwargs.get("show_locals", False))
if "show_locals" in self.traceback_kwargs:
return cast(bool, self.traceback_kwargs["show_locals"])

# If setting is not present, then return its default value.
traceback_sig = inspect.signature(Traceback.__init__)
show_locals = traceback_sig.parameters["show_locals"].default
return cast(bool, show_locals)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth saying anything in the CHANGELOG.md about this fix?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I only added this setting in beta 5.


@traceback_show_locals.setter
def traceback_show_locals(self, value: bool) -> None:
Expand Down
13 changes: 10 additions & 3 deletions tests/test_cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,22 @@ def test_set_allow_style(base_app, new_val, is_valid, expected) -> None:


def test_set_traceback_show_locals(base_app: cmd2.Cmd) -> None:
# Use the set command to alter traceback_show_locals
"""Test the set command for reading and setting traceback_show_locals."""
import inspect

from rich.traceback import Traceback

# Get Traceback's default value for "show_locals"
traceback_sig = inspect.signature(Traceback.__init__)
default_val = traceback_sig.parameters["show_locals"].default

# Clear any existing value
base_app.traceback_kwargs.pop("show_locals", None)
assert "show_locals" not in base_app.traceback_kwargs

# Test that we receive a default value of False if not present
# Test that we receive the default value if not present
orig_val = base_app.traceback_show_locals
assert orig_val is False
assert orig_val is default_val
assert "show_locals" not in base_app.traceback_kwargs

# Test setting it
Expand Down
Loading