Victor Stinner schrieb am 23.06.20 um 11:18:
Maybe an object can generate a temporary PyObject** view which requires to allocate resources (like memory) and the release function would release these resources.
I agree that this is more explicit when it comes to resource management, but there is nothing that beats direct native data structure access when it comes to speed. If a "PyObject*" is not what the runtime uses internally as data structure, then why hand it out as an interface to users who require performance? There's PyIter_Next() already for those who don't.
If the intention is to switch to a more efficient internal data structure inside of CPython (or expose in PyPy whatever that uses), then I would look more at PEP-393 for a good interface here, or "array.array". It's perfectly fine to have 20 different internal array types, as long as they are explicitly and safely exposed to users.