Andrew Barnert wrote on 09/26/2014 10:16 PM:
On Sep 26, 2014, at 12:12, Nathaniel Smith
mailto:njs@pobox.com> wrote: On 26 Sep 2014 19:15, "Nathaniel Smith"
mailto:njs@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@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/