diff --git a/Doc/library/cmd.rst b/Doc/library/cmd.rst index 66544f82f6ff3f..3ceb1197dbcf50 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) @@ -127,6 +139,8 @@ A :class:`Cmd` instance has the following methods: 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 will cause + the previous command to be repeated and passed again to this method. .. method:: Cmd.completedefault(text, line, begidx, endidx) 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.

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