◐ Shell
clean mode source ↗

gh-79932: raise exception if frame.clear() is called on a suspended frame by iritkatriel · Pull Request #111792 · python/cpython

Another option is to expose the frame state to python, so that the caller can avoid calling clear on a suspended frame.

Yeah, given that we have an API here to manipulate the frame, and a reason for not using that API when the frame is suspended, it makes sense to allow the caller to detect the frame is in that state. At least that feels better than having a custom flag to turn the warning into an error.

But: I'm not sure this requires deprecation even. It's just a bug, right? frame_clear() looks like it is intended to clear the locals only after the frame has exited -- if it's still running, we don't want to interfere with it. But a suspended frame, in this context, should be seen as not having exited. The actual state check is just wrong, it incorrectly categorizes "suspended" together with "exited" instead of "running". Since the function is already expected to raise RuntimeError, I don't see why we need to tread so lightly around fixing this (to me) obvious bug.