Skip to content

gh-120606: Allow EOF to exit pdb commands definition #120607

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 19, 2024

Conversation

gaogaotiantian
Copy link
Member

@gaogaotiantian gaogaotiantian commented Jun 16, 2024

@@ -860,6 +860,9 @@ def handle_command_def(self, line):
return False # continue to handle other cmd def in the cmd list
elif cmd == 'end':
return True # end of cmd list
elif cmd == 'EOF':
print('')
return True # end of cmd list
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(1) why do we need two instructions to do the same thing?
(2) why add a feature and not document it?
(3) where is the test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(1) Because EOF is a special command triggered when user "inputs" EOF (Ctrl+D on Linux). It's not something we added, it's something we need to deal with. Users will do Ctrl+D as a habit from all the other similar usages and expect a reasonable result. Currently the behavior is pretty bad.

(Pdb) commands 1
(com) (com) (com) (com) (com) (com) 

(2) Like I said, this is a reaction to a very natural user input. I think that's a very expected behavior. However, we can add something in commands command saying that inputting an EOF character will also exit the commands command.

(3) The test involving EOF is not easy to test, especially if you still want to input something after. Currently pdb does not really test it. One way around this is to use "EOF" as an explicit command to simulate the EOF user inputs. That would make the test super trivial to write. We are relying on cmd.Cmd to convert Ctrl+D (Ctrl+Z on Windows I believe) to the correct EOF command. Does that sound reasonable to you?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. That context can be encoded in a test. Add the trivial test for 'EOF' and put a comment there that this is what cmd produces for Ctrl+D.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I added a basic test in an existing test case. Notice that <BLANKLINE> appears in the output because EOF\n creates a new line but Ctrl-D will not have that new line. So EOF\n results in an extra new line compared to Ctrl-D. We don't want the user to stay on the same line after Ctrl-D so we need to output a new line in that command.

@gaogaotiantian
Copy link
Member Author

Thanks for the review!

@gaogaotiantian gaogaotiantian merged commit 4bbb027 into python:main Jun 19, 2024
35 checks passed
@gaogaotiantian gaogaotiantian deleted the pdb-commands-def-eof branch June 19, 2024 22:50
mrahtz pushed a commit to mrahtz/cpython that referenced this pull request Jun 30, 2024
noahbkim pushed a commit to hudson-trading/cpython that referenced this pull request Jul 11, 2024
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants