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-108463: Make expressions/statements work as expected in pdb by gaogaotiantian · Pull Request #108464 · python/cpython

Conversation

@gaogaotiantian

@gaogaotiantian gaogaotiantian commented Aug 25, 2023 •
edited by bedevere-bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

This PR makes expressions like

c.a
c['a']
n()
j=1
r"a"

work in pdb.

  • Issue: Make expressions in pdb work as people would expect #108463

Sorry, something went wrong.

Uh oh!

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

All reactions
gaogaotiantian added 2 commits August 24, 2023 16:59
@gaogaotiantian
Make expressions work as expected in pdb
02e334f
@gaogaotiantian
Add "=" for assignment
3c0a551
@bedevere-bot bedevere-bot mentioned this pull request Aug 25, 2023
Make expressions in pdb work as people would expect #108463
Closed
@bedevere-bot bedevere-bot added the awaiting review label Aug 25, 2023
@blurb-it
📜🤖 Added by blurb_it.
03cd1ba
@gaogaotiantian
gaogaotiantian requested a review from iritkatriel August 25, 2023 00:15
@gaogaotiantian

gaogaotiantian commented Aug 25, 2023

Copy link
Copy Markdown
Member Author

Hi @iritkatriel , this is a very straighforward feature (implementation wise) and the code change is trivial. It's only about whether we should do it or not. Could you give it a review when you have some time? Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

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

chgnrdv
chgnrdv reviewed Sep 1, 2023
View reviewed changes
Comment thread Lib/pdb.py Resolved

Uh oh!

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

@iritkatriel

iritkatriel commented Sep 1, 2023

Copy link
Copy Markdown
Member

Hi @iritkatriel , this is a very straighforward feature (implementation wise) and the code change is trivial. It's only about whether we should do it or not. Could you give it a review when you have some time? Thanks!

Sorry only saw this now.

Can this break anything?

All reactions

Sorry, something went wrong.

Uh oh!

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

@gaogaotiantian
Add more characters to command list
5604e93
@gaogaotiantian

gaogaotiantian commented Sep 1, 2023

Copy link
Copy Markdown
Member Author

Sorry only saw this now.

Can this break anything?

I can't think of any meaningful case that this could break. This change only affects how "cmd" parse commands - basically what characters can be considered as the command. In pdb, we expect users to use space to separate commands and args. All the supported commands only contain letters.

So in real world, this will only make a difference when the user types a string that contains characters other than letters, numbers and underscores, for example, c['a']. In such cases, the user always almost want to evaluate the expression(or execute the statement), but forget that c is a command.

This feature basically changed the behavior when the user types such statements/expressions - it does not report "command invalid" anymore - it runs the statement/expression.

All reactions

Sorry, something went wrong.

Uh oh!

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

@iritkatriel

iritkatriel commented Sep 3, 2023

Copy link
Copy Markdown
Member

This needs to be documented quite prominently as a new feature because it changes behaviour quite visibly. Someone might be surprised that something now executes code when it was previously a NOP.

All reactions

Sorry, something went wrong.

Uh oh!

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

@gaogaotiantian

gaogaotiantian commented Sep 3, 2023 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member Author

This needs to be documented quite prominently as a new feature because it changes behaviour quite visibly. Someone might be surprised that something now executes code when it was previously a NOP.

I think the behavior after this change actually is closer to what the current documentation claims.

Arguments to commands must be separated by whitespace (spaces or tabs)

This defines how pdb should treat commands and arguments, which is not what we are doing now. According to the current docs, if the user inputs c['a'], it should be treated as a "command" because there's no whitespace anywhere. However, the current behavior treats it as command c + argument ['a'], which is against the docs.

I don't think anyone would be surprised if they input c['a'] and pdb evaluates the expression. If anything, this change eliminates a lot of surprises. The user would be pretty surprised if they do c['a'] and pdb complaints that it does not recognize the argument ['a'].

We also claimed in the docs that

Commands that the debugger doesn’t recognize are assumed to be Python statements and are executed in the context of the program being debugged

which is exactly what this change tries to do - c['a'] is not a command the debugger recognizes and should be considered as a Python expression.

Why would the user expect different behavior when they do d['a'] (currently evaluates the expression) and c['a'] (currently reports an error)? That's not intuitive.

I honestly can not think of a single case where the user would feel surprised with this change, even if they are very used to the old pdb.

All reactions

Sorry, something went wrong.

Uh oh!

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

@iritkatriel

iritkatriel commented Sep 3, 2023

Copy link
Copy Markdown
Member

I'm not disputing the value of the change. But it's a change in behaviour which needs to be documented (a versionchanged entry, a what's new in 3.13 entry).

Maybe someone will be surprised by the 3.12 behaviour, or the change between 3.12 and 3.13. It should be clear from the docs that this is a deliberate change.

All reactions

Sorry, something went wrong.

Uh oh!

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

@gaogaotiantian

gaogaotiantian commented Sep 3, 2023

Copy link
Copy Markdown
Member Author

I'm not disputing the value of the change. But it's a change in behaviour which needs to be documented (a versionchanged entry, a what's new in 3.13 entry).

Maybe someone will be surprised by the 3.12 behaviour, or the change between 3.12 and 3.13. It should be clear from the docs that this is a deliberate change.

Okay, I'm a bit confused about what to document, as this is more like a "bug fix" to make pdb behave like it claimed.

Maybe

pdb will execute the Python statement even if the first piece of the statement (seperated by spaces) starts with a pdb command.

This is basically what this feature fixes. I'm not sure how to organize the explanation as it's doing what the docs say. Any suggestsions on the matter?

All reactions

Sorry, something went wrong.

Uh oh!

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

@iritkatriel

iritkatriel commented Sep 4, 2023

Copy link
Copy Markdown
Member

I think something like:

.. versionchanged 3.13

   Expressions whose prefix is a pdb command are now correctly identified and executed.

And something similar in what's new in 3.13.

All reactions

Sorry, something went wrong.

Uh oh!

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

iritkatriel
iritkatriel reviewed Sep 4, 2023
View reviewed changes
Comment thread Lib/test/test_pdb.py Resolved

Uh oh!

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

gaogaotiantian added 3 commits September 4, 2023 13:58
@gaogaotiantian
Add test cases for expr with full commands
f603f1e
@gaogaotiantian
Add docs and what's new for the feature
37d17f4
@gaogaotiantian
Merge branch 'main' into pdb-improve-commands
caf41e6
iritkatriel
iritkatriel reviewed Sep 4, 2023
View reviewed changes
Comment thread Doc/library/pdb.rst Resolved

Uh oh!

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

iritkatriel
iritkatriel approved these changes Sep 4, 2023
View reviewed changes
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting review labels Sep 4, 2023
@iritkatriel
iritkatriel enabled auto-merge (squash) September 4, 2023 21:26
@iritkatriel iritkatriel added the stdlib Standard Library Python modules in the Lib/ directory label Sep 4, 2023
@iritkatriel
iritkatriel merged commit 6304d98 into python:main Sep 4, 2023
@bedevere-bot bedevere-bot removed the awaiting merge label Sep 4, 2023
@gaogaotiantian
gaogaotiantian deleted the pdb-improve-commands branch September 4, 2023 23:39
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
+1 more reviewer
@chgnrdv chgnrdv chgnrdv left review comments
Reviewers whose approvals may not affect merge requirements

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

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.

4 participants

@gaogaotiantian @iritkatriel @chgnrdv @bedevere-bot
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.