[Import-SIG] PEP 451 (ModuleSpec) round 3

Nick Coghlan ncoghlan at gmail.com
Mon Sep 2 15:57:22 CEST 2013


On 2 September 2013 23:15, Antoine Pitrou <solipsis at pitrou.net> wrote:
> Le Mon, 2 Sep 2013 23:09:18 +1000,
> Nick Coghlan <ncoghlan at gmail.com> a écrit :
>> > Er... There may (or even will) be compatibility issues with that.
>> > Such as pickling of top level functions, or the various
>> > discrepancies of bound methods vs. plain functions. Or, of course,
>> > all the changes in introspection results that might disrupt
>> > existing code (think the various `inspect` functions).
>> >
>> > I think it would be much safer to have top level functions remain
>> > plain functions, and take the module object as first argument as
>> > they already do (the "PyObject *self"). And it would help extension
>> > modules be more like normal Python modules.
>>
>> Yeah, I made that suggestion when I was confused between which of
>> PyModule_GetState and PyState_GetModule caused problems. Since it's
>> only the latter, there's no need to muck about with exposing bound
>> methods of objects with hidden state - we already have that by calling
>> "PyModule_GetState" on the module parameter.
>
> But even PyModule_GetState isn't necessary anymore, if module objects
> can have custom C fields.

You're giving me too much credit here - I *really* wasn't thinking
clearly about the problem, and had managed to forget that module level
functions still receive the module as their first argument, so they
can already get access to custom fields if the module is an instance
of a custom type. Just a mindset problem caused by the fact we'd
started the discussion based on the idea of returning an instance of a
completely custom type, but it still lead to some remarkably erroneous
suggestions :)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Import-SIG mailing list