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

Make frame.f_locals.copy() return a snapshot dict of f_locals #118921

Closed
gaogaotiantian opened this issue May 10, 2024 · 0 comments
Closed

Make frame.f_locals.copy() return a snapshot dict of f_locals #118921

gaogaotiantian opened this issue May 10, 2024 · 0 comments
Assignees
Labels
type-feature A feature request or enhancement

Comments

@gaogaotiantian
Copy link
Member

gaogaotiantian commented May 10, 2024

Feature or enhancement

Proposal:

Per PEP 667, frame.f_locals is now a write-through proxy (FrameLocalsProxy) for underlying fast local variables. In the beginning we did not implement the copy() method because we think dict(frame.f_locals) is a more explicit way to achieve the snapshot. However, there are existing code that's using frame.f_locals.copy() to take a snapshot. Moreover, types.MappingProxyType({}).copy() returns the copy of the underlying mapping so it's not unprecedented for a proxy.copy() to return a dict.

Thus, we should implement copy() method for FrameLocalsProxy and make it return a dict of snapshot of the current local variables.

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

https://discuss.python.org/t/pep-667-consistent-views-of-namespaces/46631/26

Linked PRs

@gaogaotiantian gaogaotiantian added the type-feature A feature request or enhancement label May 10, 2024
@gaogaotiantian gaogaotiantian self-assigned this May 10, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 10, 2024
…-118923)

(cherry picked from commit 35c4361)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
gvanrossum pushed a commit that referenced this issue May 10, 2024
…) (#118933)

(cherry picked from commit 35c4361)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants