GeezerVison is showing github.com — gh-102980: Redirect pdb `interact` command, add tests and improve docs by gaogaotiantian · Pull Request #111194 · python/cpython
Conversation
With the long due #102896, we can finally add tests for interact command.
However, the current interact command uses code.interact directly which makes it super difficult to test, because code.interact writes to sys.stderr directly (with sys.stderr.write)! We need to overload the write method in a derived class to write to the same channel as Pdb.message.
The interactive message is also changed to make more sense - one might wonder if this is a breaking change to users, but
- This PR will be not backported, so it's a new thing.
- The current status (plus the interactive issue in gh-102895 Add an option local_exit in code.interact to block exit() from terminating the whole process #102896 before the fix) made it almost impossible to write tests for
interact command, so I don't think we'll break anything.
This PR adds the class for interact commmand and some basic tests for interact; and also clarifies the namespace situation with interact - it's a bit tricky and could be confusing to the users, so some clarification is needed.
The way to exit interact command is also added to the docs.
📚 Documentation preview 📚: https://cpython-previews--111194.org.readthedocs.build/
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
gaogaotiantian
changed the title
gh-102980: Add tests and some extra notes for pdb's interact command
gh-102980: Redirect pdb interact command, add tests and improve docs
Oct 23, 2023
|
Hi @iritkatriel , could you maybe take a look at this PR when you have some time? It's a relatively straightforward one and it's been stuck for a while. Thanks!
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
@@ -0,0 +1 @@ |
|
|
Redirect the output of ``interact`` command of :mod:`pdb` to the same channel as the debugger. Add tests and improve docs.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this describing the code change in this PR?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. So currently pdb uses code.interact directly for interact command. However, code.interact has a hard-coded output to sys.stderr. pdb supports defining output channel, and we kind of use that for our tests. The user would also expect the output from interact command flushed to the same channel as pdb (stdout instead of stderr by default actually).
This PR subclassed code.InteractiveConsole to overwrite the write method, in order to redirect the output to self.message.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
aisk
pushed a commit
to aisk/cpython
that referenced
this pull request
Feb 11, 2024
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
stdlib
Standard Library Python modules in the Lib/ directory
tests
Tests in the Lib/test dir
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|