GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-102980: Redirect pdb `interact` command, add tests and improve docs by gaogaotiantian · Pull Request #111194 · python/cpython

Conversation

@gaogaotiantian

@gaogaotiantian gaogaotiantian commented Oct 23, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

  • Issue: Improve test coverage on pdb #102980

📚 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.

All reactions
gaogaotiantian added 2 commits October 22, 2023 17:18
@gaogaotiantian
Add tests and some extra notes for interact
f9b3123
@gaogaotiantian
Update docs
4edbbc0
@gaogaotiantian
gaogaotiantian requested a review from brandtbucher October 23, 2023 00:26
@bedevere-app bedevere-app Bot mentioned this pull request Oct 23, 2023
Improve test coverage on pdb #102980
Closed
@bedevere-app bedevere-app Bot added awaiting review tests Tests in the Lib/test dir labels Oct 23, 2023
@gaogaotiantian gaogaotiantian added the skip news label Oct 23, 2023
@gaogaotiantian gaogaotiantian closed this Oct 23, 2023
@gaogaotiantian
Fix interact output
a56a294
@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 gaogaotiantian reopened this Oct 23, 2023
@gaogaotiantian gaogaotiantian removed the skip news label Oct 23, 2023
blurb-it Bot and others added 2 commits October 23, 2023 03:49
@blurb-it
📜🤖 Added by blurb_it.
4611d18
@gaogaotiantian
Remove blank line from the output
2eca91f
@gaogaotiantian

gaogaotiantian commented Dec 5, 2023

Copy link
Copy Markdown
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!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iritkatriel
iritkatriel reviewed Dec 6, 2023
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2023-10-23-03-49-34.gh-issue-102980.aXBd54.rst
@@ -0,0 +1 @@
Redirect the output of ``interact`` command of :mod:`pdb` to the same channel as the debugger. Add tests and improve docs.

@iritkatriel iritkatriel Dec 6, 2023

Copy link
Copy Markdown
Member

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.

All reactions

@gaogaotiantian gaogaotiantian Dec 6, 2023

Copy link
Copy Markdown
Member Author

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.

All reactions
iritkatriel
iritkatriel approved these changes Dec 6, 2023
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Dec 6, 2023
@iritkatriel
Merge branch 'main' into pdb-interact-test
c3eb762
@iritkatriel iritkatriel added the stdlib Standard Library Python modules in the Lib/ directory label Dec 6, 2023
iritkatriel
iritkatriel reviewed Dec 6, 2023
View reviewed changes
Comment thread Doc/library/pdb.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@gaogaotiantian
Update docs about version info
03e1dc0
iritkatriel
iritkatriel reviewed Dec 7, 2023
View reviewed changes
Comment thread Doc/library/pdb.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

iritkatriel added 2 commits December 7, 2023 11:02
@iritkatriel
Update Doc/library/pdb.rst
cde8ecf
@iritkatriel
Merge branch 'main' into pdb-interact-test
b4a14c6
@iritkatriel
iritkatriel enabled auto-merge (squash) December 7, 2023 11:03
@iritkatriel
iritkatriel merged commit 3d712a9 into python:main Dec 7, 2023
@bedevere-app bedevere-app Bot removed the awaiting merge label Dec 7, 2023
@gaogaotiantian

gaogaotiantian commented Dec 7, 2023

Copy link
Copy Markdown
Member Author

Thanks for the review!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@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
@gaogaotiantian @aisk
pythongh-102980: Redirect output of pdb's interact command, add tes…
ed9935e
…ts and improve docs (python#111194)
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
@gaogaotiantian @Glyphack
pythongh-102980: Redirect output of pdb's interact command, add tes…
a432107
…ts and improve docs (python#111194)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@iritkatriel iritkatriel iritkatriel approved these changes
@brandtbucher brandtbucher Awaiting requested review from brandtbucher

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

Projects

None yet

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.

2 participants

@gaogaotiantian @iritkatriel
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.