bpo-13214: raise EOFError in Lib/cmd.py #17074
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current behavior of the cmd module is to return the string 'EOF'
when the program receives an EOF (e.g. when you press ctrl + d,
or when the end of a file is reached). When you're writing some kind of
REPL, you often want to exit when when you get an EOF (for example,
python's REPL exits when you press ctrl + d). The way to
achieve that functionality here is to create a function
called
do_EOF
in your subclass ofcmd.Cmd
, and callexit()
If you want some other behavior when you get an EOF, you can put
that in
do_EOF
instead.This is problematic for two main reasons:
EOF
shows up as an undocumented command when you typehelp
. It'snot that big of a deal, but it's definitely not ideal (and perhaps
confusing).
EOF
into the terminal, it will call yourdo_EOF
function. If your
do_EOF
function exits, typingdo_EOF
will exit theprogram. Seems rather silly.
I propose the cmd class NOT catch the EOFError. That will eliminate both
of the above problems.
See also https://bugs.python.org/issue13214 and #13536
https://bugs.python.org/issue13214