-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
Labels
type-feature
A feature request or enhancement
Comments
gvanrossum
pushed a commit
that referenced
this issue
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 <[email protected]>
gvanrossum
pushed a commit
that referenced
this issue
May 10, 2024
…) (#118933) (cherry picked from commit 35c4361) Co-authored-by: Tian Gao <[email protected]>
5 tasks
rominf
added a commit
to rominf/sentry-python
that referenced
this issue
Jul 10, 2024
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
added a commit
to rominf/sentry-python
that referenced
this issue
Jul 10, 2024
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 issue
Jul 16, 2024
…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 issue
Jul 16, 2024
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 issue
Jul 17, 2024
arjennienhuis
pushed a commit
to arjennienhuis/sentry-python
that referenced
this issue
Sep 30, 2024
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]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 thecopy()
method because we thinkdict(frame.f_locals)
is a more explicit way to achieve the snapshot. However, there are existing code that's usingframe.f_locals.copy()
to take a snapshot. Moreover,types.MappingProxyType({}).copy()
returns the copy of the underlying mapping so it's not unprecedented for aproxy.copy()
to return a dict.Thus, we should implement
copy()
method forFrameLocalsProxy
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
copy()
method forFrameLocalsProxy
#118923copy()
method forFrameLocalsProxy
(GH-118923) #118933The text was updated successfully, but these errors were encountered: