[Python-ideas] Extend module objects to support properties
Nick Coghlan
ncoghlan at gmail.com
Fri Feb 1 04:07:37 CET 2013
On Fri, Feb 1, 2013 at 12:58 PM, Eric Snow <ericsnowcurrently at gmail.com> wrote:
>
> On Jan 31, 2013 5:50 PM, "Nick Coghlan" <ncoghlan at gmail.com> wrote:
>>
>> On Fri, Feb 1, 2013 at 5:56 AM, Eric Snow <ericsnowcurrently at gmail.com>
>> wrote:
>> > That said, Larry's original proposal relates to sys, a built-in module
>> > written in C (in CPython of course). In that case the solution is not
>> > quite the same, since module initialization interacts with sys.modules
>> > differently. [1][2] Accommodating the original request would require
>> > more work, whether to muck with the import C-API or making sys an
>> > instance of another type, as someone suggested.
>>
>> sys is already special cased so heavily in the interpreter
>> initialization, making it a little more special really wouldn't bother
>> me much :)
>>
>> As far as customising other extension modules goes, the same "replace
>> yourself in sys.modules" trick should still work, you'd just do it via
>> the C API from your module init function.
>
> Don't extension modules get added to sys.modules only after their init
> function returns?
Oh, you're right, they're currently responsible for creating their own
module object (I was thinking of the way I *wished* extension module
imports worked). Returning the module object from the init function
still works though - we just need to make sure the extension loader
can cope with the init function returning a non-module object :)
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list