
On Sun, 31 Jan 2021 at 14:09, Nick Coghlan <ncoghlan@gmail.com> wrote:
On Sat, 30 Jan 2021, 10:55 pm Nick Coghlan, <ncoghlan@gmail.com> wrote:
On Sat, 30 Jan 2021, 10:18 pm Mark Shannon, <mark@hotpy.org> wrote:
The break in compatibility with locals() seems much more intrusive, yet you are OK with that (as am I). PyEval_GetLocals() is part of the stable ABI and returns a borrowed reference. That means there are a lot of implementation restrictions around keeping that API working. A follow-up PEP could propose deprecating and removing the API as intrinsically broken, but I don't want to go that far in PEP 558. After sleeping on this, I'm now convinced that you're right, and we can reasonably drop the "stash extra info in the frame locals snapshot" feature from the *new* optimised frame locals C API.
The PR at https://github.com/python/peps/pull/1787 has been updated to accept your suggestion into the PEP rather than listing it as an open question. It also cleans up a bunch more references to the old "store the proxy on the frame" idea that I missed when moving away from the idea. I haven't updated the reference implementation at https://github.com/python/cpython/pull/3640/files to match though, and don't know when I might get to doing that myself. If you're interested in tackling that, the offer of PEP co-authorship definitely still stands :) While I haven't listed it in the PR as an open issue, there is one potential point for simplification that I haven't resolved yet: whether the new APIs should *completely* ignore the shared dynamic snapshot that ``PyEval_GetLocals()`` uses. At the moment, most of the APIs (including the Python ``locals()`` builtin) will still see extra values written via that backwards compatibility interface, as they implicitly update it, and then use it to generate their final return value. The only APIs that will ignore it completely are the Python level frame.f_locals, and the C level PyLocals_GetView() and PyFrame_GetLocalsView(), as those rely on the new fast locals proxy, and bypass the dynamic snapshot. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia