Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

bpo-13214: raise EOFError in Lib/cmd.py#17074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
kimbo wants to merge1 commit intopython:masterfromkimbo:kl/raise-EOFError-in-cmd

Conversation

kimbo
Copy link

@kimbokimbo commentedNov 7, 2019
edited by bedevere-bot
Loading

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
calleddo_EOF in your subclass ofcmd.Cmd, and callexit()
If you want some other behavior when you get an EOF, you can put
that indo_EOF instead.

This is problematic for two main reasons:

  1. EOF shows up as an undocumented command when you typehelp. It's
    not that big of a deal, but it's definitely not ideal (and perhaps
    confusing).
  2. If you typeEOF into the terminal, it will call yourdo_EOF
    function. If yourdo_EOF function exits, typingdo_EOF will exit the
    program. Seems rather silly.

I propose the cmd class NOT catch the EOFError. That will eliminate both
of the above problems.

See alsohttps://bugs.python.org/issue13214 and#13536

https://bugs.python.org/issue13214

positron96 reacted with thumbs up emoji
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 ofREPL, you often want to exit when when you get an EOF (for example,python's REPL exits when you press ctrl + d). The way toachieve that functionality here is to create a functioncalled `do_EOF` in your subclass of `cmd.Cmd`, and call `exit()`If you want some other behavior when you get an EOF, you can putthat in `do_EOF` instead.This is problematic for two main reasons:1. `EOF` shows up as an undocumented command when you type `help`. It'snot that big of a deal, but it's definitely not ideal (and perhapsconfusing).2. If you type `EOF` into the terminal, it will call your `do_EOF`function. If your `do_EOF` function exits, typing `do_EOF` will exit theprogram. Seems rather silly.I propose the cmd class NOT catch the EOFError. That will eliminate bothof the above problems. I realize this could be an issue with backwardscompatibility and such, but I don't think it would require muchadjustment (maybe a couple lines).See alsohttps://bugs.python.org/issue13214 andpython#13536
@the-knights-who-say-ni

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed thePSF contributor agreement (CLA).

Recognized GitHub username

We couldn't find abugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@kimbo

This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please followthe steps outlined in the CPython devguide to rectify this issue.

You cancheck yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@kimbo
Copy link
Author

i signed the CLA and created a BPO account with my gh username

@kimbo
Copy link
Author

On the other hand, it might break less things to add in#13536. Closing this because I don't think it would be worth it to break everyone's existing subclasses of cmd.Cmd.

@kimbokimbo closed thisNov 11, 2019
@kimbokimbo deleted the kl/raise-EOFError-in-cmd branchNovember 11, 2019 13:44
@positron96
Copy link

I'd also find the current situation with EOFs uncomfortable to use

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@kimbo@the-knights-who-say-ni@positron96@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp