Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
gh-118921: Addcopy()
method forFrameLocalsProxy
#118923
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
@gvanrossum do we want to support |
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 usingcopy.copy()
for the same purpose, andmappingproxy
doesn't support it either.
Lib/test/test_frame.py Outdated
x = 0 | ||
d = sys._getframe().f_locals | ||
d_copy = d.copy() | ||
self.assertIs(type(d_copy), dict) |
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.
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.
Thanks@gaogaotiantian for the PR, and@gvanrossum for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
GH-118933 is a backport of this pull request to the3.13 branch. |
Starting from Python 3.13, `frame.f_locals` is not `dict` anymore, but`FrameLocalsProxy`, that cannot be copied using `copy.copy()`. In Python3.13 and later, it should be copied using a method `.copy()`. The new wayof copying works the same as the old one for versions of Python prior to3.13, according to the documentation (both copying methods produce ashallow copy).See:https://peps.python.org/pep-0667/python/cpython#118921python/cpython#118923https://docs.python.org/3.13/whatsnew/3.13.html#porting-to-python-3-13https://docs.python.org/3/library/copy.html
Starting from Python 3.13, `frame.f_locals` is not `dict` anymore, but`FrameLocalsProxy`, that cannot be copied using `copy.copy()`. In Python3.13 and later, it should be copied using a method `.copy()`. The new wayof copying works the same as the old one for versions of Python prior to3.13, according to the documentation (both copying methods produce ashallow copy).Since Python 3.13, `FrameLocalsProxy` skips items of `locals()` that havenon-`str` keys; this is a CPython implementation detail, so we hencedisable `test_non_string_variables` test on Python 3.13.See:https://peps.python.org/pep-0667/python/cpython#118921python/cpython#118923https://docs.python.org/3.13/whatsnew/3.13.html#porting-to-python-3-13https://docs.python.org/3/library/copy.htmlhttps://github.com/python/cpython/blame/7b413952e817ae87bfda2ac85dd84d30a6ce743b/Objects/frameobject.c#L148
…3271)Starting from Python 3.13, `frame.f_locals` is not `dict` anymore, but`FrameLocalsProxy`, that cannot be copied using `copy.copy()`. In Python3.13 and later, it should be copied using a method `.copy()`. The new wayof copying works the same as the old one for versions of Python prior to3.13, according to the documentation (both copying methods produce ashallow copy).Since Python 3.13, `FrameLocalsProxy` skips items of `locals()` that havenon-`str` keys; this is a CPython implementation detail, so we hencedisable `test_non_string_variables` test on Python 3.13.See:https://peps.python.org/pep-0667/python/cpython#118921python/cpython#118923https://docs.python.org/3.13/whatsnew/3.13.html#porting-to-python-3-13https://docs.python.org/3/library/copy.htmlhttps://github.com/python/cpython/blame/7b413952e817ae87bfda2ac85dd84d30a6ce743b/Objects/frameobject.c#L148
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#16600Starting from Python 3.13, `frame.f_locals` is not `dict` anymore, but`FrameLocalsProxy`, that cannot be copied using `copy.copy()`. In Python3.13 and later, it should be copied using a method `.copy()`. The new wayof copying works the same as the old one for versions of Python prior to3.13, according to the documentation (both copying methods produce ashallow copy).Since Python 3.13, `FrameLocalsProxy` skips items of `locals()` that havenon-`str` keys; this is a CPython implementation detail, so we hencedisable `test_non_string_variables` test on Python 3.13.See:https://peps.python.org/pep-0667/python/cpython#118921python/cpython#118923https://docs.python.org/3.13/whatsnew/3.13.html#porting-to-python-3-13https://docs.python.org/3/library/copy.htmlhttps://github.com/python/cpython/blame/7b413952e817ae87bfda2ac85dd84d30a6ce743b/Objects/frameobject.c#L148---------Co-authored-by: Roman Inflianskas <rominf@pm.me>
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#16600Starting from Python 3.13, `frame.f_locals` is not `dict` anymore, but`FrameLocalsProxy`, that cannot be copied using `copy.copy()`. In Python3.13 and later, it should be copied using a method `.copy()`. The new wayof copying works the same as the old one for versions of Python prior to3.13, according to the documentation (both copying methods produce ashallow copy).Since Python 3.13, `FrameLocalsProxy` skips items of `locals()` that havenon-`str` keys; this is a CPython implementation detail, so we hencedisable `test_non_string_variables` test on Python 3.13.See:https://peps.python.org/pep-0667/python/cpython#118921python/cpython#118923https://docs.python.org/3.13/whatsnew/3.13.html#porting-to-python-3-13https://docs.python.org/3/library/copy.htmlhttps://github.com/python/cpython/blame/7b413952e817ae87bfda2ac85dd84d30a6ce743b/Objects/frameobject.c#L148---------Co-authored-by: Roman Inflianskas <rominf@pm.me>
Partial cherry-pick of:a98f660Adding preliminary support for Python 3.13.The `_partialmethod` attribute of methods wrapped with `partialmethod()`was renamed to `__partialmethod__` in CPython 3.13:python/cpython#16600Starting from Python 3.13, `frame.f_locals` is not `dict` anymore, but`FrameLocalsProxy`, that cannot be copied using `copy.copy()`. In Python3.13 and later, it should be copied using a method `.copy()`. The new wayof copying works the same as the old one for versions of Python prior to3.13, according to the documentation (both copying methods produce ashallow copy).Since Python 3.13, `FrameLocalsProxy` skips items of `locals()` that havenon-`str` keys; this is a CPython implementation detail, so we hencedisable `test_non_string_variables` test on Python 3.13.See:https://peps.python.org/pep-0667/python/cpython#118921python/cpython#118923https://docs.python.org/3.13/whatsnew/3.13.html#porting-to-python-3-13https://docs.python.org/3/library/copy.htmlhttps://github.com/python/cpython/blame/7b413952e817ae87bfda2ac85dd84d30a6ce743b/Objects/frameobject.c#L148
Partial cherry-pick of:a98f660Adding preliminary support for Python 3.13.The `_partialmethod` attribute of methods wrapped with `partialmethod()`was renamed to `__partialmethod__` in CPython 3.13:python/cpython#16600Starting from Python 3.13, `frame.f_locals` is not `dict` anymore, but`FrameLocalsProxy`, that cannot be copied using `copy.copy()`. In Python3.13 and later, it should be copied using a method `.copy()`. The new wayof copying works the same as the old one for versions of Python prior to3.13, according to the documentation (both copying methods produce ashallow copy).Since Python 3.13, `FrameLocalsProxy` skips items of `locals()` that havenon-`str` keys; this is a CPython implementation detail, so we hencedisable `test_non_string_variables` test on Python 3.13.See:https://peps.python.org/pep-0667/python/cpython#118921python/cpython#118923https://docs.python.org/3.13/whatsnew/3.13.html#porting-to-python-3-13https://docs.python.org/3/library/copy.htmlhttps://github.com/python/cpython/blame/7b413952e817ae87bfda2ac85dd84d30a6ce743b/Objects/frameobject.c#L148
Partial cherry-pick of:a98f660Adding preliminary support for Python 3.13.The `_partialmethod` attribute of methods wrapped with `partialmethod()`was renamed to `__partialmethod__` in CPython 3.13:python/cpython#16600Starting from Python 3.13, `frame.f_locals` is not `dict` anymore, but`FrameLocalsProxy`, that cannot be copied using `copy.copy()`. In Python3.13 and later, it should be copied using a method `.copy()`. The new wayof copying works the same as the old one for versions of Python prior to3.13, according to the documentation (both copying methods produce ashallow copy).Since Python 3.13, `FrameLocalsProxy` skips items of `locals()` that havenon-`str` keys; this is a CPython implementation detail, so we hencedisable `test_non_string_variables` test on Python 3.13.See:https://peps.python.org/pep-0667/python/cpython#118921python/cpython#118923https://docs.python.org/3.13/whatsnew/3.13.html#porting-to-python-3-13https://docs.python.org/3/library/copy.htmlhttps://github.com/python/cpython/blame/7b413952e817ae87bfda2ac85dd84d30a6ce743b/Objects/frameobject.c#L148
Uh oh!
There was an error while loading.Please reload this page.
frame.f_locals.copy()
return a snapshot dict off_locals
#118921