gh-102864: Remove access to f_locals in pdb by gaogaotiantian · Pull Request #102865 · python/cpython (original) (raw)

So, I had a draft for the proxy solution. It's a bit more aggressive than the original fix.

The solution introduced two new classes in bdb.py - FrameProxy and TracebackProxy. They are very similar to the original FrameObject and TracebackObject, except it won't load f_locals twice. One noticeable compromise is inspect.getsourcelines() needs the actual frame object(unless we do a really ugly __unwrap__ hack in FrameProxy).

As you can tell, it's not completely backward compatible. pdb.py requires some changes to accomodate, for example, convert tracebacks to the proxy, and get the real frame for the source code.

Like I said, this approach is definitely more aggressive than the original, but it gives a pretty good protection about f_locals. pdb won't need to worry about it anymore(actually I changed the code to cache f_locals to use f_locals directly as it's more intuitive).

Not sure if this is something we want to pursue. I do have a solution that only has the proxy in pdb(HEAD~3 I think). We can use that if this is too much.