[Python-Dev] redesigning the extension module initialisation protocol

Stefan Behnel stefan_ml at behnel.de
Mon Aug 12 06:51:47 CEST 2013


Nick Coghlan, 12.08.2013 00:41:
> On 11 Aug 2013 09:55, "Stefan Behnel" wrote:
>>>>> this already suggests a simple module initialisation interface.
>>>>> The
>>>>> extension module would expose a function that returns a module type,
>>>>> and
>>>>> the loader/importer would then simply instantiate that. Nothing else
>>>>> is needed.
>>>> Actually, strike the word "module type" and replace it with "type".
>> [...]
>> Next, we need to define a signature for the type's __init__() method.
> 
> We need the "ModuleSpec" object to pass here, which is what we're currently
> working on in import-sig.

Ok but that's just the very final step. All the rest is C-API specific.

And for clarification: you want to let the importer create the ModuleSpec
object and the pass it into the module's __init__ method?

I guess it could also be passed into the type creation function then,
right? Since it wouldn't harm to do that, I think it's a good idea to
provide as much information to the extension module as possible, as early
as we can, and that's the first time we talk to the shared library.

I've started writing up a pre-PEP that describes this protocol. I think it
makes sense to keep it separate from the ModuleSpec PEP as the latter can
easily be accepted without changing anything at the C-API level, but it
shouldn't happen the other way round.

Stefan




More information about the Python-Dev mailing list