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

Don't access current_frame f_locals #13021

Merged
merged 4 commits into from
Jun 23, 2021
Merged

Don't access current_frame f_locals #13021

merged 4 commits into from
Jun 23, 2021

Conversation

Carreau
Copy link
Member

@Carreau Carreau commented Jun 15, 2021

This should fix #13020

Though it's a suttle enough bug that tests needs to be written.
And we can't rely on doctests as they are not ran.

This should fix ipython#13020

Though it's a suttle enough bug that tests needs to be written.
And we can't rely on doctests as they are not ran.
@Carreau Carreau added this to the 7.25.0 milestone Jun 15, 2021
@MrMino
Copy link
Member

MrMino commented Jun 19, 2021

I'm still not sure if I understand why accessing f_locals would reset the scope. Is this related to https://bugs.python.org/issue5215?

I wonder why I never noticed this.

@Carreau
Copy link
Member Author

Carreau commented Jun 22, 2021

This is probably related, but Pdb in cpython use self.curframe_locals as well, so it's likely on purpose.

@Carreau
Copy link
Member Author

Carreau commented Jun 22, 2021

Test added.

Carreau and others added 2 commits June 22, 2021 13:58
Co-authored-by: Blazej Michalik <6691643+MrMino@users.noreply.github.com>
@MrMino
Copy link
Member

MrMino commented Jun 23, 2021

For anyone interested, and for the future me - it's the call to PyFrame_FastToLocalsWithError in frame_getlocals, i.e. the C implementation of frame.f_locals "property", that refreshes its value.

This has few other funny quirks that might bite us in the future, if pdb fixes any and we manage to shadow the patch in ipdb. There's a draft PEP for fixing the f_locals semantics that mentions them in the references: PEP-558, related paragraph.

Carreau added a commit that referenced this pull request Jun 24, 2021
…021-on-7.x

Backport PR #13021 on branch 7.x (Don't access current_frame f_locals)
@Carreau Carreau deleted the flocals branch December 9, 2021 00:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

accessing f_locals in debugger resets namespace
2 participants