Skip to content

Commit ba6003b

Browse files
committed
Merge branch 'main' into 1627-silence-settable
2 parents cf47df5 + cc88ca6 commit ba6003b

4 files changed

Lines changed: 36 additions & 21 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,8 @@ prompt is displayed.
8181
- `cmd2` no longer sets a default title for a subparsers group. If you desire a title, you will
8282
need to pass one in like this `parser.add_subparsers(title="subcommands")`. This is standard
8383
`argparse` behavior.
84-
- Added `HelpFormatterRenderable` protocol and `HelpContent` type alias to support context-aware
85-
help content in `argparse`.
86-
- `TextGroup` now implements `HelpFormatterRenderable`.
84+
- `TextGroup` now implements `HelpFormatterRenderable` (see Enhancements section below for more
85+
details).
8786
- Removed `formatter_creator` parameter from `TextGroup.__init__()`.
8887
- Removed `Cmd2ArgumentParser.create_text_group()` method.
8988
- `argparse` and `Rich` integration refactoring:
@@ -145,6 +144,8 @@ prompt is displayed.
145144
full type hints and IDE autocompletion for `self._cmd` without needing to override and cast
146145
the property.
147146
- Added `traceback_kwargs` attribute to allow customization of Rich-based tracebacks.
147+
- Added `HelpFormatterRenderable` protocol and `HelpContent` type alias to support context-aware
148+
help content in `argparse`.
148149
- The `print()` function available in a `pyscript` writes to `self.stdout` and respects the
149150
`allow_style` setting. It also supports printing `Rich` objects.
150151
- Added `Cmd2ArgumentParser.output_to()` context manager to temporarily set the output stream

cmd2/cmd2.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,20 +1240,20 @@ def always_prefix_settables(self) -> bool:
12401240
return self._always_prefix_settables
12411241

12421242
@always_prefix_settables.setter
1243-
def always_prefix_settables(self, new_value: bool) -> None:
1243+
def always_prefix_settables(self, value: bool) -> None:
12441244
"""Set whether CommandSet settable values should always be prefixed.
12451245
1246-
:param new_value: True if CommandSet settable values should always be prefixed. False if not.
1246+
:param value: True if CommandSet settable values should always be prefixed. False if not.
12471247
:raises ValueError: If a registered CommandSet does not have a defined prefix
12481248
"""
1249-
if not self._always_prefix_settables and new_value:
1249+
if not self._always_prefix_settables and value:
12501250
for cmd_set in self._installed_command_sets:
12511251
if not cmd_set.settable_prefix:
12521252
raise ValueError(
12531253
f"Cannot force settable prefixes. CommandSet {cmd_set.__class__.__name__} does "
12541254
f"not have a settable prefix defined."
12551255
)
1256-
self._always_prefix_settables = new_value
1256+
self._always_prefix_settables = value
12571257

12581258
@property
12591259
def settables(self) -> Mapping[str, Settable]:
@@ -1357,14 +1357,20 @@ def allow_style(self) -> ru.AllowStyle:
13571357
return ru.ALLOW_STYLE
13581358

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

13641364
@property
13651365
def traceback_show_locals(self) -> bool:
13661366
"""Property needed to support do_set when it reads traceback_show_locals."""
1367-
return cast(bool, self.traceback_kwargs.get("show_locals", False))
1367+
if "show_locals" in self.traceback_kwargs:
1368+
return cast(bool, self.traceback_kwargs["show_locals"])
1369+
1370+
# If setting is not present, then return its default value.
1371+
traceback_sig = inspect.signature(Traceback.__init__)
1372+
show_locals = traceback_sig.parameters["show_locals"].default
1373+
return cast(bool, show_locals)
13681374

13691375
@traceback_show_locals.setter
13701376
def traceback_show_locals(self, value: bool) -> None:

mkdocs.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,15 @@ markdown_extensions:
125125

126126
# Validation
127127
validation:
128-
nav:
129-
omitted_files: info
130-
not_found: warn
131-
absolute_links: info
132-
links:
133-
not_found: warn
134-
absolute_links: ignore
135-
unrecognized_links: info
128+
invalid_link_anchors: true
129+
invalid_links: true
130+
shadowed_definitions: true
131+
shadowed_footnotes: true
132+
unresolved_footnotes: true
133+
# bug with mkdocstrings autorefs: https://github.com/zensical/zensical/issues/600
134+
unresolved_references: false
135+
unused_definitions: true
136+
unused_footnotes: true
136137

137138
not_in_nav: |
138139
**/download/*.md

tests/test_cmd2.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,22 @@ def test_set_allow_style(base_app, new_val, is_valid, expected) -> None:
243243

244244

245245
def test_set_traceback_show_locals(base_app: cmd2.Cmd) -> None:
246-
# Use the set command to alter traceback_show_locals
246+
"""Test the set command for reading and setting traceback_show_locals."""
247+
import inspect
248+
249+
from rich.traceback import Traceback
250+
251+
# Get Traceback's default value for "show_locals"
252+
traceback_sig = inspect.signature(Traceback.__init__)
253+
default_val = traceback_sig.parameters["show_locals"].default
247254

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

252-
# Test that we receive a default value of False if not present
259+
# Test that we receive the default value if not present
253260
orig_val = base_app.traceback_show_locals
254-
assert orig_val is False
261+
assert orig_val is default_val
255262
assert "show_locals" not in base_app.traceback_kwargs
256263

257264
# Test setting it

0 commit comments

Comments
 (0)