Converting a static extension type to a heap exension type

I’ve found the documentation here on how to change a static extension type into a heap type. However, I’m having trouble working out the mechanics of actually how to do the conversion based on those docs. It would be really nice to see a version of the extension types tutorial that uses heap types, but that’s not covered there. Is anyone aware of another resource I could look at to compare the implementation of a static type and heap type in a a C extension module?

Thanks!

1 Like

I have code for heap types in PyCXX. You may find its code helps.
Search for PyType_Spec to find your way into the code.

Download source from PyCXX Python-C++ Connection download | SourceForge.net

Thanks for bringing this up. These docs definitely need to be updated to reflect current recommended practise (using heap types, module state, and multi-phase init). There are multiple issues[1][2] regarding such doc updates, but unfortunately nothing has been done yet.


  1. "Embedding Python in Another Application" documentation examples use deprecated functions · Issue #95709 · python/cpython · GitHub ↩︎

  2. "Embedding Python in Another Application" documentation examples use deprecated functions · Issue #95709 · python/cpython · GitHub ↩︎

There’s an example of how to write an extension module using the Limited API in the CPython source:

For the legacy approach, see cpython/xxmodule.c at main · python/cpython · GitHub.