Skip to content

Commit b1e07db

Browse files
committed
Renamed two patch functions.
1 parent 403210a commit b1e07db

4 files changed

Lines changed: 18 additions & 18 deletions

File tree

cmd2/argparse_custom.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
**Completion**
2626
2727
cmd2 uses its ArgparseCompleter class to enable argparse-based completion
28-
on all commands that use the @with_argparse wrappers. Out of the box you get
28+
on all commands that use the @with_argparser decorator. Out of the box you get
2929
completion of commands, subcommands, and flag names, as well as instructive
3030
hints about the current argument that print when tab is pressed. In addition,
3131
you can add completion for each argument's values using parameters passed
@@ -211,15 +211,15 @@ def get_choices(self) -> Choices:
211211
**Patched argparse functions**
212212
213213
``argparse._ActionsContainer.add_argument`` - adds arguments related to tab
214-
completion and enables nargs range parsing. See _add_argument_wrapper for
215-
more details on these arguments.
214+
completion and enables nargs range parsing. See ``__ActionsContainer_add_argument``
215+
for more details on these arguments.
216216
217217
**Added accessor methods**
218218
219219
cmd2 has patched ``argparse.Action`` to include the following accessor methods
220220
for cases in which you need to manually access the cmd2-specific attributes.
221221
222-
- ``argparse.Action.get_choices_callable()`` - See ``action_get_choices_callable`` for more details.
222+
- ``argparse.Action.get_choices_callable()`` - See ``_action_get_choices_callable`` for more details.
223223
- ``argparse.Action.set_choices_provider()`` - See ``_action_set_choices_provider`` for more details.
224224
- ``argparse.Action.set_completer()`` - See ``_action_set_completer`` for more details.
225225
- ``argparse.Action.get_table_columns()`` - See ``_action_get_table_columns`` for more details.
@@ -665,15 +665,15 @@ def _action_set_custom_parameter(self: argparse.Action, value: Any) -> None:
665665

666666

667667
############################################################################################################
668-
# Patch _ActionsContainer.add_argument with our wrapper to support more arguments
668+
# Patch _ActionsContainer.add_argument to support more arguments
669669
############################################################################################################
670670

671671

672-
# Save original _ActionsContainer.add_argument so we can call it in our wrapper
672+
# Save original _ActionsContainer.add_argument so we can call it in our patch
673673
orig_actions_container_add_argument = argparse._ActionsContainer.add_argument
674674

675675

676-
def _add_argument_wrapper(
676+
def __ActionsContainer_add_argument( # noqa: N802
677677
self: argparse._ActionsContainer,
678678
*args: Any,
679679
nargs: int | str | tuple[int] | tuple[int, int] | tuple[int, float] | None = None,
@@ -683,7 +683,7 @@ def _add_argument_wrapper(
683683
table_columns: Sequence[str | Column] | None = None,
684684
**kwargs: Any,
685685
) -> argparse.Action:
686-
"""Wrap ActionsContainer.add_argument() to support cmd2-specific settings.
686+
"""Patch ActionsContainer.add_argument() to support cmd2-specific settings.
687687
688688
# Args from original function
689689
:param self: instance of the _ActionsContainer being added to
@@ -801,8 +801,8 @@ def _add_argument_wrapper(
801801
return new_arg
802802

803803

804-
# Overwrite _ActionsContainer.add_argument with our wrapper
805-
setattr(argparse._ActionsContainer, 'add_argument', _add_argument_wrapper)
804+
# Overwrite _ActionsContainer.add_argument with our patch
805+
setattr(argparse._ActionsContainer, 'add_argument', __ActionsContainer_add_argument)
806806

807807

808808
############################################################################################################

cmd2/cmd2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,8 +2716,8 @@ def get_help_topics(self) -> list[str]:
27162716

27172717
def sigint_handler(
27182718
self,
2719-
signum: int, # noqa: ARG002,
2720-
frame: FrameType | None, # noqa: ARG002,
2719+
signum: int, # noqa: ARG002
2720+
frame: FrameType | None, # noqa: ARG002
27212721
) -> None:
27222722
"""Signal handler for SIGINTs which typically come from Ctrl-C events.
27232723

cmd2/rich_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,12 @@ def prepare_objects_for_rendering(*objects: Any) -> tuple[Any, ...]:
494494
# Text.from_ansi() monkey patch
495495
###################################################################################
496496

497-
# Save original Text.from_ansi() so we can call it in our wrapper
497+
# Save original Text.from_ansi() so we can call it in our patch
498498
_orig_text_from_ansi = Text.from_ansi
499499

500500

501501
@classmethod # type: ignore[misc]
502-
def _from_ansi_wrapper(cls: type[Text], text: str, *args: Any, **kwargs: Any) -> Text: # noqa: ARG001
502+
def _Text_from_ansi(cls: type[Text], text: str, *args: Any, **kwargs: Any) -> Text: # noqa: N802, ARG001
503503
r"""Wrap Text.from_ansi() to fix its trailing newline bug.
504504
505505
This wrapper handles an issue where Text.from_ansi() removes the
@@ -539,4 +539,4 @@ def _from_ansi_has_newline_bug() -> bool:
539539

540540
# Only apply the monkey patch if the bug is present
541541
if _from_ansi_has_newline_bug():
542-
Text.from_ansi = _from_ansi_wrapper # type: ignore[assignment]
542+
Text.from_ansi = _Text_from_ansi # type: ignore[assignment]

tests/test_rich_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ def test_set_theme() -> None:
115115
assert ru.APP_THEME.styles[rich_style_key] == theme[rich_style_key]
116116

117117

118-
def test_from_ansi_wrapper() -> None:
118+
def test_from_ansi_patch() -> None:
119119
# Check if we are still patching Text.from_ansi(). If this check fails, then Rich
120-
# has fixed the bug. Therefore, we can remove this test function and ru._from_ansi_wrapper.
121-
assert Text.from_ansi.__func__ is ru._from_ansi_wrapper.__func__ # type: ignore[attr-defined]
120+
# has fixed the bug. Therefore, we can remove this test function and ru._Text_from_ansi.
121+
assert Text.from_ansi.__func__ is ru._Text_from_ansi.__func__ # type: ignore[attr-defined]
122122

123123
# Line breaks recognized by str.splitlines().
124124
# Source: https://docs.python.org/3/library/stdtypes.html#str.splitlines

0 commit comments

Comments
 (0)