[Python-ideas] Implicit submodule imports

Thomas Gläßle t_glaessle at gmx.de
Fri Sep 26 23:03:50 CEST 2014




Andrew Barnert wrote on 09/26/2014 10:16 PM:
> On Sep 26, 2014, at 12:12, Nathaniel Smith <njs at pobox.com
> <mailto:njs at pobox.com>> wrote:
>
>> On 26 Sep 2014 19:15, "Nathaniel Smith" <njs at pobox.com
>> <mailto:njs at pobox.com>> wrote:
>> > The proposal is that before exec'ing __init__.py, we check for the
>> existence of a __preinit__.py,
>>
>> Silly me, obviously the right and proper name for this file would be
>> __new__.py.
>>
>
> I had an email written just to say "this sounds brilliant, but why
> isn't it called __new__", with three paragraphs explaining why it was
> a good analogy... Now I guess I can delete draft. :)
>
> Anyway, I definitely like this better than re-classing modules in
> mid-initialization, and better than my magic comment hack (and looking
> at the code again, of course you're right that my magic comment hack
> was necessary with anything like my approach, I guess I just forgot in
> the intervening time).
I like this one. Imagine, we had a class LazyModule (or w/e name) class
in the stdlib. One could just do:

    __new__.py:
        from importlib import LazyModule as __metamodule__ # (or
__metapackage?)


Maybe, LazyModule could resolve only attributes, that are explicitly
given in __all__ (or more explicitly __autoimport__?).



>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140926/ac515171/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 949 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140926/ac515171/attachment.sig>


More information about the Python-ideas mailing list