Skip to content
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

GH-101673: Fix pdb bug that local variable changes lost after longlist #101674

Merged
merged 7 commits into from
Mar 12, 2023

Conversation

gaogaotiantian
Copy link
Member

@gaogaotiantian gaogaotiantian commented Feb 8, 2023

The bug is described in #101673.

Using f_code.co_name to check whether it's a frame module avoids reading f_local whose side effect reverts local variable changes in pdb.

@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@cpython-cla-bot
Copy link

cpython-cla-bot bot commented Feb 8, 2023

All commit authors signed the Contributor License Agreement.
CLA signed

@arhadthedev arhadthedev added the stdlib Python modules in the Lib dir label Feb 8, 2023
@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@artemmukhin
Copy link
Contributor

@iritkatriel I am wondering if you could be an appropriate reviewer for this. Could you please take a look?

@iritkatriel
Copy link
Member

Thanks for adding the test. Before merging this I would need to spend some time to understand why this happened and to convince myself that this is the right solution. If someone else reviews it before I get around to it that's obviously fine.

@artemmukhin
Copy link
Contributor

@iritkatriel Thank you for your quick response.

I have investigated the issue further and discovered that the problematic obj.f_globals is obj.f_locals check was introduced in 5ed2b5a to work around the limitation of inspect.getsourcelines, as the latter did not check that the given frame is a module-level frame.

However, inspect.getsourcelines was independently corrected in 91cb298 using the same object.f_code.co_name == "<module>" technique.

So I believe that we should consider replacing the custom pdb.getsourcelines function with direct inspect.getsourcelines invocations. After making this change, the updated test_pdb still passes. @gaogaotiantian WDYT?

@gaogaotiantian
Copy link
Member Author

Yeah I think that’s the way to go. The original customized pdb version was to avoid module level frame issue and it would be nice to not to keep multiple identical code pieces around. The functionality seems to be the same. I’ll make the changes to use inspect version directly and remove the pdb version.

@gaogaotiantian
Copy link
Member Author

As @ortem said, the reason we had a separate getsourcelines in pdb was because the inspect version did not deal with the module level frame. It does now so we can just switch back to inspect version and kept one less duplicated code piece. I did include the regression test for the issue.

Copy link
Member

@iritkatriel iritkatriel left a comment

Choose a reason for hiding this comment

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

Makes sense. Thank you!

@iritkatriel iritkatriel added 3.11 only security fixes 3.12 bugs and security fixes needs backport to 3.11 only security fixes type-bug An unexpected behavior, bug, or error needs backport to 3.10 only security fixes and removed 3.11 only security fixes 3.12 bugs and security fixes labels Mar 12, 2023
@iritkatriel iritkatriel merged commit 5d677c5 into python:main Mar 12, 2023
@miss-islington
Copy link
Contributor

Thanks @gaogaotiantian for the PR, and @iritkatriel for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry, @gaogaotiantian and @iritkatriel, I could not cleanly backport this to 3.10 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 5d677c556f03a34d1c2d86e4cc96025870c20c12 3.10

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 12, 2023
…ter longlist (pythonGH-101674)

(cherry picked from commit 5d677c5)

Co-authored-by: gaogaotiantian <gaogaotiantian@hotmail.com>
@bedevere-bot
Copy link

GH-102632 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Mar 12, 2023
iritkatriel pushed a commit to iritkatriel/cpython that referenced this pull request Mar 12, 2023
miss-islington added a commit that referenced this pull request Mar 12, 2023
…nglist (GH-101674)

(cherry picked from commit 5d677c5)

Co-authored-by: gaogaotiantian <gaogaotiantian@hotmail.com>
@bedevere-bot
Copy link

GH-102633 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Mar 12, 2023
pablogsal pushed a commit that referenced this pull request Mar 13, 2023
…fter longlist (#101674) (#102633)

GH-101673: Fix pdb bug where local variable changes are lost after longlist (#101674)

(cherry picked from commit 5d677c5)

Co-authored-by: gaogaotiantian <gaogaotiantian@hotmail.com>
@gaogaotiantian gaogaotiantian deleted the fix-issue-101673 branch March 23, 2023 23:29
warsaw pushed a commit to warsaw/cpython that referenced this pull request Apr 11, 2023
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 type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants