Skip to content

gh-102980: Redirect pdb interact command, add tests and improve docs #111194

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 9 commits into from
Dec 7, 2023

Conversation

gaogaotiantian
Copy link
Member

@gaogaotiantian gaogaotiantian commented Oct 23, 2023

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

  1. This PR will be not backported, so it's a new thing.
  2. 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/

@gaogaotiantian 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
@gaogaotiantian
Copy link
Member Author

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!

@@ -0,0 +1 @@
Redirect the output of ``interact`` command of :mod:`pdb` to the same channel as the debugger. Add tests and improve docs.
Copy link
Member

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?

Copy link
Member Author

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.

@iritkatriel iritkatriel added the stdlib Python modules in the Lib dir label Dec 6, 2023
@iritkatriel iritkatriel enabled auto-merge (squash) December 7, 2023 11:03
@iritkatriel iritkatriel merged commit 3d712a9 into python:main Dec 7, 2023
@gaogaotiantian
Copy link
Member Author

Thanks for the review!

@gaogaotiantian gaogaotiantian deleted the pdb-interact-test branch December 7, 2023 19:13
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants