
There's more background in the Discourse thread [1], but the key C API design topic is that PyEval_GetLocals() and PyEval_GetGlobals() currently behave differently when there's no Python frame active in the current thread:
- PyEval_GetGlobals(): returns NULL without setting an exception
- PyEval_GetLocals(): returns NULL *and* sets an exception
PyEval_GetLocals() has been doing the latter since it gained the ability to report memory allocation errors when dealing with optimised frames back in Python 3.4.
The "no active Python frame" case isn't really an error (as it's a valid state in applications that embed CPython), so I'm wondering if PyEval_GetLocals() should partially go back to its pre-3.4 behaviour, and not set an exception in the "no active Python frame" case.
Cheers, Nick.
[1] https://discuss.python.org/t/subtle-c-api-discrepancy-pyeval-getlocals-vs-py...
-- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia