PEP 553 built-in debug() function (bpo-31353) by warsaw · Pull Request #3355 · python/cpython (original) (raw)
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that true, i.e. that it's possible to call this with an exception set?
In my experience, it's very common that a function returning a result and set an exception is not catched immediately, but somewhere "later". I had such issues when I ran my pyfailmalloc tool which injects MemoryError anywhere.
But I made many changes in CPython internals to add assert(!PyErr_Occurred()) at many places. The main change is that all functions calling functions should now check that no exception is raised if the called function returned a result. This is _Py_CheckFunctionResult().
To come back to your breakpoint() implementation, "assert(!PyErr_Occurred());" should be enough.