Python: upgrade to match modern practices
Much needs to be done for abi3 builds to really work.
WrappingPythonCore:
- store internal
PyTypeObject*
heap types on thevtkCommonCore
module itself - convert basic types to heap types (this will also simplify multiple inheritance, which is impractical for static types)
As for the generated code:
Porting types:
- the
Py_TPFLAGS_IMMUTABLETYPE
flag is implicit in static types, so we'll need to pay attention and add it where needed - getting access to base type pointers will need some work as they'll be stored in module state of other modules
- may be able to just do
PyObject_GetAttrString(depmod, "baseclass")
or something to get thePyTypeObject*
we need
- may be able to just do
Porting modules:
- move to multi-phase initialization (PEP 489)
- store module state on the modules themselves (PEP 573)
- caches and whatnot should also be stored on the relevant modules (though probably just
vtkCommonCore
?) (PEP 630)
Landmark Python versions:
- 3.9 introduced
sometype.__module__
which gets access to the module object and therefore the state. - 3.9 introduced
PyCMethod
which gives the defining classPyTypeObject*
to methods (to more easily access the state)- See this feature request for making it more accessible; 3.13 at the earliest
- 3.10 allows
PyType_GetSlot
on static types - 3.11 puts the buffer API into the stable ABI
Relevant PEPs:
- PEP 384: Defining a Stable ABI
- PEP 489: Multi-phase extension module initialization
- PEP 573: Module State Access from C Extension Methods
- PEP 630: Isolating Extension Modules
Other links:
- https://github.com/markshannon/New-C-API-for-Python
- Scrapping the C API and writing a C bindings generator and then using
cffi
on that
Cc: @dgobbi @banesullivan
Edited by David Gobbi