C-API for initializing statically linked extension modules

The internals here feel very unstable to me, in the sense that we’d just replace the whole thing with a more direct approach if we had infinite resources. Plus we’ve already essentially deprecated single-phase init (both subinterpreters and nogil will block/severely warn about it, IIUC).

I think Context is intended to mean it’s opaque, so this renaming probably sacrifices that. But I suspect it’s fully internal right now, so making it public at all necessitates adding more functions to create/set/free it.

Is there a higher level function we can offer, perhaps - PyImport_ImportByInitFunc(const char *fullname, initfunc func)? That way a customer importer can find/know the function itself and turn it into a module object, which seems to be the main aim here. (Presumably such a function already exists for ourselves to import from inittab.)

(Also agree on getting @eric.snow’s thoughts, particularly around how likely we are to refactor import and/or totally deprecate single-phase init.)

1 Like