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-118921: Add `copy()` method for `FrameLocalsProxy` by gaogaotiantian · Pull Request #118923 · python/cpython

Conversation

@gaogaotiantian

@gaogaotiantian gaogaotiantian commented May 10, 2024 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member
  • Issue: Make frame.f_locals.copy() return a snapshot dict of f_locals #118921

Sorry, something went wrong.

Uh oh!

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

All reactions
@gaogaotiantian
Add copy() method for FrameLocalsProxy
aa0348d
@gaogaotiantian
gaogaotiantian requested a review from markshannon as a code owner May 10, 2024 19:53
@bedevere-app bedevere-app Bot added the awaiting review label May 10, 2024
@bedevere-app bedevere-app Bot mentioned this pull request May 10, 2024
Make frame.f_locals.copy() return a snapshot dict of f_locals #118921
Closed
@blurb-it
📜🤖 Added by blurb_it.
3ecbe35
@gaogaotiantian
gaogaotiantian requested a review from gvanrossum May 10, 2024 19:54
@gaogaotiantian

gaogaotiantian commented May 10, 2024

Copy link
Copy Markdown
Member Author

@gvanrossum do we want to support copy.copy(proxy) as well?

All reactions

Sorry, something went wrong.

Uh oh!

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

gvanrossum
gvanrossum reviewed May 10, 2024
View reviewed changes

@gvanrossum gvanrossum left a comment

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.

LG, one nit. I don't think there's much evidence that people are using copy.copy() for the same purpose, and mappingproxy doesn't support it either.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Lib/test/test_frame.py Outdated
x = 0
d = sys._getframe().f_locals
d_copy = d.copy()
self.assertIs(type(d_copy), dict)

@gvanrossum gvanrossum May 10, 2024

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.

I think assertIsInstance is good enough here.

Sorry, something went wrong.

Uh oh!

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

All reactions

@gaogaotiantian gaogaotiantian May 10, 2024

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.

Right, I did not use that method a lot so I didn't think of it.

Sorry, something went wrong.

Uh oh!

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

All reactions
@gvanrossum gvanrossum added the 3.13 only security fixes label May 10, 2024
@gaogaotiantian
Use assertIsInstance
75b7121
gvanrossum
gvanrossum approved these changes May 10, 2024
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels May 10, 2024
@gvanrossum
gvanrossum merged commit 35c4361 into python:main May 10, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label May 10, 2024
@gvanrossum gvanrossum added the needs backport to 3.13 only security fixes label May 10, 2024
@miss-islington-app

miss-islington-app Bot commented May 10, 2024

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

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

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 10, 2024
@gaogaotiantian @miss-islington
pythongh-118921: Add copy() method for FrameLocalsProxy (pythonGH…
cee09fe
…-118923)

(cherry picked from commit 35c4361)

Co-authored-by: Tian Gao <[email protected]>
@bedevere-app

bedevere-app Bot commented May 10, 2024

Copy link
Copy Markdown

GH-118933 is a backport of this pull request to the 3.13 branch.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 only security fixes label May 10, 2024
gvanrossum pushed a commit that referenced this pull request May 10, 2024
@miss-islington @gaogaotiantian
[3.13] gh-118921: Add copy() method for FrameLocalsProxy (GH-118923…
93ef7aa
…) (#118933)

(cherry picked from commit 35c4361)

Co-authored-by: Tian Gao <[email protected]>
szef1233
szef1233 approved these changes May 11, 2024
View reviewed changes
@gaogaotiantian
gaogaotiantian deleted the framelocalsproxy-copy branch May 12, 2024 20:44
@JelleZijlstra JelleZijlstra mentioned this pull request May 28, 2024
backport a9a74da 3.13 #119642
Closed
rominf added a commit to rominf/sentry-python that referenced this pull request Jul 10, 2024
@rominf
fix(tests): Fix exception on copying frame.f_locals (Python 3.13)
5536c2a
Starting from Python 3.13, `frame.f_locals` is not `dict` anymore, but
`FrameLocalsProxy`, that cannot be copied using `copy.copy()`. In Python
3.13 and later, it should be copied using a method `.copy()`. The new way
of copying works the same as the old one for versions of Python prior to
3.13, according to the documentation (both copying methods produce a
shallow copy).

See:
https://peps.python.org/pep-0667/
python/cpython#118921
python/cpython#118923
https://docs.python.org/3.13/whatsnew/3.13.html#porting-to-python-3-13
https://docs.python.org/3/library/copy.html
@rominf rominf mentioned this pull request Jul 10, 2024
fix(tests): Fix exception on copying frame.f_locals (Python 3.13) getsentry/sentry-python#3271
Merged
rominf added a commit to rominf/sentry-python that referenced this pull request Jul 10, 2024
@rominf
fix(tests): Fix exception on copying frame.f_locals (Python 3.13)
13d7a2f
Starting from Python 3.13, `frame.f_locals` is not `dict` anymore, but
`FrameLocalsProxy`, that cannot be copied using `copy.copy()`. In Python
3.13 and later, it should be copied using a method `.copy()`. The new way
of copying works the same as the old one for versions of Python prior to
3.13, according to the documentation (both copying methods produce a
shallow copy).

Since Python 3.13, `FrameLocalsProxy` skips items of `locals()` that have
non-`str` keys; this is a CPython implementation detail, so we hence
disable `test_non_string_variables` test on Python 3.13.

See:
https://peps.python.org/pep-0667/
python/cpython#118921
python/cpython#118923
https://docs.python.org/3.13/whatsnew/3.13.html#porting-to-python-3-13
https://docs.python.org/3/library/copy.html
https://github.com/python/cpython/blame/7b413952e817ae87bfda2ac85dd84d30a6ce743b/Objects/frameobject.c#L148
sentrivana pushed a commit to getsentry/sentry-python that referenced this pull request Jul 16, 2024
@rominf
fix(tests): Fix exception on copying frame.f_locals (Python 3.13) (#…
49b4cf3
…3271)

Starting from Python 3.13, `frame.f_locals` is not `dict` anymore, but
`FrameLocalsProxy`, that cannot be copied using `copy.copy()`. In Python
3.13 and later, it should be copied using a method `.copy()`. The new way
of copying works the same as the old one for versions of Python prior to
3.13, according to the documentation (both copying methods produce a
shallow copy).

Since Python 3.13, `FrameLocalsProxy` skips items of `locals()` that have
non-`str` keys; this is a CPython implementation detail, so we hence
disable `test_non_string_variables` test on Python 3.13.

See:
https://peps.python.org/pep-0667/
python/cpython#118921
python/cpython#118923
https://docs.python.org/3.13/whatsnew/3.13.html#porting-to-python-3-13
https://docs.python.org/3/library/copy.html
https://github.com/python/cpython/blame/7b413952e817ae87bfda2ac85dd84d30a6ce743b/Objects/frameobject.c#L148
sentrivana added a commit to getsentry/sentry-python that referenced this pull request Jul 16, 2024
@sentrivana @rominf
feat: Preliminary support for Python 3.13 (#3200)
a98f660
Adding preliminary support for Python 3.13.

The `_partialmethod` attribute of methods wrapped with `partialmethod()`
was renamed to `__partialmethod__` in CPython 3.13:
python/cpython#16600

Starting from Python 3.13, `frame.f_locals` is not `dict` anymore, but
`FrameLocalsProxy`, that cannot be copied using `copy.copy()`. In Python
3.13 and later, it should be copied using a method `.copy()`. The new way
of copying works the same as the old one for versions of Python prior to
3.13, according to the documentation (both copying methods produce a
shallow copy).

Since Python 3.13, `FrameLocalsProxy` skips items of `locals()` that have
non-`str` keys; this is a CPython implementation detail, so we hence
disable `test_non_string_variables` test on Python 3.13.

See:
https://peps.python.org/pep-0667/
python/cpython#118921
python/cpython#118923
https://docs.python.org/3.13/whatsnew/3.13.html#porting-to-python-3-13
https://docs.python.org/3/library/copy.html
https://github.com/python/cpython/blame/7b413952e817ae87bfda2ac85dd84d30a6ce743b/Objects/frameobject.c#L148

---------

Co-authored-by: Roman Inflianskas <[email protected]>
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
@gaogaotiantian @estyxx
pythongh-118921: Add copy() method for FrameLocalsProxy (python#1…
78f500a
…18923)
arjennienhuis pushed a commit to arjennienhuis/sentry-python that referenced this pull request Sep 30, 2024
@sentrivana @rominf @arjenzorgdoc
feat: Preliminary support for Python 3.13 (getsentry#3200)
869e366
Adding preliminary support for Python 3.13.

The `_partialmethod` attribute of methods wrapped with `partialmethod()`
was renamed to `__partialmethod__` in CPython 3.13:
python/cpython#16600

Starting from Python 3.13, `frame.f_locals` is not `dict` anymore, but
`FrameLocalsProxy`, that cannot be copied using `copy.copy()`. In Python
3.13 and later, it should be copied using a method `.copy()`. The new way
of copying works the same as the old one for versions of Python prior to
3.13, according to the documentation (both copying methods produce a
shallow copy).

Since Python 3.13, `FrameLocalsProxy` skips items of `locals()` that have
non-`str` keys; this is a CPython implementation detail, so we hence
disable `test_non_string_variables` test on Python 3.13.

See:
https://peps.python.org/pep-0667/
python/cpython#118921
python/cpython#118923
https://docs.python.org/3.13/whatsnew/3.13.html#porting-to-python-3-13
https://docs.python.org/3/library/copy.html
https://github.com/python/cpython/blame/7b413952e817ae87bfda2ac85dd84d30a6ce743b/Objects/frameobject.c#L148

---------

Co-authored-by: Roman Inflianskas <[email protected]>
turicas added a commit to turicas/sentry-python that referenced this pull request Jun 6, 2025
@turicas
feat: Preliminary support for Python 3.13 (getsentry#3200)
298a192
Partial cherry-pick of: a98f660

Adding preliminary support for Python 3.13.

The `_partialmethod` attribute of methods wrapped with `partialmethod()`
was renamed to `__partialmethod__` in CPython 3.13:
python/cpython#16600

Starting from Python 3.13, `frame.f_locals` is not `dict` anymore, but
`FrameLocalsProxy`, that cannot be copied using `copy.copy()`. In Python
3.13 and later, it should be copied using a method `.copy()`. The new way
of copying works the same as the old one for versions of Python prior to
3.13, according to the documentation (both copying methods produce a
shallow copy).

Since Python 3.13, `FrameLocalsProxy` skips items of `locals()` that have
non-`str` keys; this is a CPython implementation detail, so we hence
disable `test_non_string_variables` test on Python 3.13.

See:
https://peps.python.org/pep-0667/
python/cpython#118921
python/cpython#118923
https://docs.python.org/3.13/whatsnew/3.13.html#porting-to-python-3-13
https://docs.python.org/3/library/copy.html
https://github.com/python/cpython/blame/7b413952e817ae87bfda2ac85dd84d30a6ce743b/Objects/frameobject.c#L148
turicas added a commit to turicas/sentry-python that referenced this pull request Jun 6, 2025
@turicas
feat: Preliminary support for Python 3.13 (getsentry#3200)
3b4a05f
Partial cherry-pick of: a98f660

Adding preliminary support for Python 3.13.

The `_partialmethod` attribute of methods wrapped with `partialmethod()`
was renamed to `__partialmethod__` in CPython 3.13:
python/cpython#16600

Starting from Python 3.13, `frame.f_locals` is not `dict` anymore, but
`FrameLocalsProxy`, that cannot be copied using `copy.copy()`. In Python
3.13 and later, it should be copied using a method `.copy()`. The new way
of copying works the same as the old one for versions of Python prior to
3.13, according to the documentation (both copying methods produce a
shallow copy).

Since Python 3.13, `FrameLocalsProxy` skips items of `locals()` that have
non-`str` keys; this is a CPython implementation detail, so we hence
disable `test_non_string_variables` test on Python 3.13.

See:
https://peps.python.org/pep-0667/
python/cpython#118921
python/cpython#118923
https://docs.python.org/3.13/whatsnew/3.13.html#porting-to-python-3-13
https://docs.python.org/3/library/copy.html
https://github.com/python/cpython/blame/7b413952e817ae87bfda2ac85dd84d30a6ce743b/Objects/frameobject.c#L148
turicas added a commit to turicas/sentry-python that referenced this pull request Jun 6, 2025
@turicas
feat: Preliminary support for Python 3.13 (getsentry#3200)
09787da
Partial cherry-pick of: a98f660

Adding preliminary support for Python 3.13.

The `_partialmethod` attribute of methods wrapped with `partialmethod()`
was renamed to `__partialmethod__` in CPython 3.13:
python/cpython#16600

Starting from Python 3.13, `frame.f_locals` is not `dict` anymore, but
`FrameLocalsProxy`, that cannot be copied using `copy.copy()`. In Python
3.13 and later, it should be copied using a method `.copy()`. The new way
of copying works the same as the old one for versions of Python prior to
3.13, according to the documentation (both copying methods produce a
shallow copy).

Since Python 3.13, `FrameLocalsProxy` skips items of `locals()` that have
non-`str` keys; this is a CPython implementation detail, so we hence
disable `test_non_string_variables` test on Python 3.13.

See:
https://peps.python.org/pep-0667/
python/cpython#118921
python/cpython#118923
https://docs.python.org/3.13/whatsnew/3.13.html#porting-to-python-3-13
https://docs.python.org/3/library/copy.html
https://github.com/python/cpython/blame/7b413952e817ae87bfda2ac85dd84d30a6ce743b/Objects/frameobject.c#L148
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@gvanrossum gvanrossum gvanrossum approved these changes
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner
+1 more reviewer
@szef1233 szef1233 szef1233 approved these changes
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

3.13 only security fixes

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.

3 participants

@gaogaotiantian @gvanrossum @szef1233
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.