[PEP 558 - WIP] bpo-30744: Trace hooks no longer reset closure state#3640
Closed
ncoghlan wants to merge 80 commits intopython:mainfrom
Closed
[PEP 558 - WIP] bpo-30744: Trace hooks no longer reset closure state#3640ncoghlan wants to merge 80 commits intopython:mainfrom
ncoghlan wants to merge 80 commits intopython:mainfrom
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
(Declined as per the PEP deferral notice in https://github.com/python/peps/pull/3050/files - this reference implementation was useful at the time, but after the frame management changes in Python 3.11 any implementation of the updated semantics in PEP 558 or PEP 667 would be best off starting from scratch. The test cases from this branch might still be useful, but those can always be copied out to a new branch easily enough)
Previously, trace hooks running on a nested function
could incorrectly reset the state of a closure cell.
This avoids that by changing the semantics of the
f_locals namespace on function frames to use a
write-through proxy, such that changes are made
immediately rather than being written back some
arbitrary time later.
PEP 558 and bpo-17960 cover additional changes
to locals() and frame.f_locals semantics that are
part of this update.
Remaining TODO items before this PR could be considered complete:
_PyInterpreterFrameto_Py_framedata#27525 and resync this PR with the main branchlocals(),vars(), and potentially others (check alllocalsmentions)locals()(and potentiallyvars())PyEval_*C API documentation updatesPyFrame_*C API documentation updatesFix C API header layout to follow modern conventions(bpo-35134: Migrate frameobject.h contents to cpython/frameobject.h #18052)PyFrameObjectredefinitioneval()default locals namespace toPyLocals_Get()exec()default locals namespace toPyLocals_Get()IMPORT_STARopcode is encountered in aCO_OPTIMIZEDframePyFrame_LocalsToFast()runtime errorPyLocals_Get()andPyEval_GetLocals()at different scopessetdefault()popitem()clear()update()(theoretically already implemented, but needs explicit tests)Desirable code structure improvements (current plan for these is to put any duplicated into a sharable location in this PR, but file separate maintainability issues to migrate to using the shared code in the original locations, to avoid the diff size impact on this PR):
odictobject.cMove the(obsolete task, as frame locals proxy is now independent of mapping proxy)DictProxycode out ofdescrobject.chttps://bugs.python.org/issue30744