From 4facf306c8f987aa1019b7915089782263849be5 Mon Sep 17 00:00:00 2001 From: Tan Long Date: 2026年1月14日 00:08:08 +0800 Subject: [PATCH 1/5] docs(cmd): highlight default empty-line command repetition --- Doc/library/cmd.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Doc/library/cmd.rst b/Doc/library/cmd.rst index 66544f82f6ff3f..e90d86c8b914e1 100644 --- a/Doc/library/cmd.rst +++ b/Doc/library/cmd.rst @@ -93,6 +93,18 @@ A :class:`Cmd` instance has the following methods: are the beginning and ending indexes of the prefix text, which could be used to provide different completion depending upon which position the argument is in. +.. rubric:: Empty input behavior + +When the user enters an empty line in response to the prompt, ``Cmd`` does +**not** ignore the input by default. Instead, it repeats the last non-empty +command entered. + +This behavior is implemented by :meth:`Cmd.emptyline`. Subclasses that do not +want empty input to repeat the previous command should override +:meth:`Cmd.emptyline` to do nothing:: + + def emptyline(self): + pass .. method:: Cmd.do_help(arg) From 3ad49f941d2c4ec9090aa565d4b28257032da4c8 Mon Sep 17 00:00:00 2001 From: Tan Long Date: 2026年1月14日 00:09:58 +0800 Subject: [PATCH 2/5] blurb --- .../2026-01-14-00-09-43.gh-issue-143804.KHeDcP.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Documentation/2026-01-14-00-09-43.gh-issue-143804.KHeDcP.rst diff --git a/Misc/NEWS.d/next/Documentation/2026-01-14-00-09-43.gh-issue-143804.KHeDcP.rst b/Misc/NEWS.d/next/Documentation/2026-01-14-00-09-43.gh-issue-143804.KHeDcP.rst new file mode 100644 index 00000000000000..d6b9149cb25962 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2026-01-14-00-09-43.gh-issue-143804.KHeDcP.rst @@ -0,0 +1,2 @@ +Clarified the documentation of :mod:`cmd` regarding the default handling of +empty input lines. From be404492dfdbf4c38e8c9b428e2973cd534f8cb9 Mon Sep 17 00:00:00 2001 From: Tan Long Date: 2026年1月14日 00:22:38 +0800 Subject: [PATCH 3/5] Mention `emptyline` behavior under `default()` documentation. --- Doc/library/cmd.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Doc/library/cmd.rst b/Doc/library/cmd.rst index e90d86c8b914e1..c6a3acb5241b8d 100644 --- a/Doc/library/cmd.rst +++ b/Doc/library/cmd.rst @@ -99,9 +99,9 @@ When the user enters an empty line in response to the prompt, ``Cmd`` does **not** ignore the input by default. Instead, it repeats the last non-empty command entered. -This behavior is implemented by :meth:`Cmd.emptyline`. Subclasses that do not +This behavior is implemented by :meth:`emptyline`. Subclasses that do not want empty input to repeat the previous command should override -:meth:`Cmd.emptyline` to do nothing:: +:meth:`emptyline` to do nothing:: def emptyline(self): pass @@ -139,6 +139,8 @@ want empty input to repeat the previous command should override Method called on an input line when the command prefix is not recognized. If this method is not overridden, it prints an error message and returns. + Note that if :meth:`emptyline` is not overridden, empty input may cause + the previous command to be repeated and passed again to this method. .. method:: Cmd.completedefault(text, line, begidx, endidx) From 283e74cfe43cf267411d755f1b4e03866d70299c Mon Sep 17 00:00:00 2001 From: Tan Long Date: 2026年1月14日 00:29:57 +0800 Subject: [PATCH 4/5] fix reference target not found: emptyline --- Doc/library/cmd.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/cmd.rst b/Doc/library/cmd.rst index c6a3acb5241b8d..f3990c3514c426 100644 --- a/Doc/library/cmd.rst +++ b/Doc/library/cmd.rst @@ -99,9 +99,9 @@ When the user enters an empty line in response to the prompt, ``Cmd`` does **not** ignore the input by default. Instead, it repeats the last non-empty command entered. -This behavior is implemented by :meth:`emptyline`. Subclasses that do not +This behavior is implemented by :meth:`Cmd.emptyline`. Subclasses that do not want empty input to repeat the previous command should override -:meth:`emptyline` to do nothing:: +:meth:`Cmd.emptyline` to do nothing:: def emptyline(self): pass From b30ebb0fde4bd56527ad9d6435fa231504b9d59b Mon Sep 17 00:00:00 2001 From: Tan Long Date: 2026年1月14日 19:18:14 +0800 Subject: [PATCH 5/5] replace 'may' with 'will' --- Doc/library/cmd.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/cmd.rst b/Doc/library/cmd.rst index f3990c3514c426..3ceb1197dbcf50 100644 --- a/Doc/library/cmd.rst +++ b/Doc/library/cmd.rst @@ -139,7 +139,7 @@ want empty input to repeat the previous command should override Method called on an input line when the command prefix is not recognized. If this method is not overridden, it prints an error message and returns. - Note that if :meth:`emptyline` is not overridden, empty input may cause + Note that if :meth:`emptyline` is not overridden, empty input will cause the previous command to be repeated and passed again to this method. .. method:: Cmd.completedefault(text, line, begidx, endidx)

AltStyle によって変換されたページ (->オリジナル) /