If I recall there was a proposal a few months for a "lazy" keyword that would render anything lazy, including imports.
Instead of just adding laziness on generators, the on imports, then who knows where, maybe it's time to consider laziness is a hell of a good general concept and try to generalize it ?
For imports, that would mean:
lazy from module import stuff lazy import foo
For the rest,
bar = lazy 1 + 1
When you think about it, it's syntaxic sugar to avoid manually wrapping everything in functions, storying stuff in closure and calling that later.
Le 12/09/2017 à 10:26, Ivan Levkivskyi a écrit :
module.__getattr__ works pretty well for normal access, after being imported by another module, but it doesn't properly trigger loading by functions defined in the module's own namespace.
The idea of my PEP is to be very simple (both semantically and in terms of implementation). This is why I don't want to add any complex logic. People who will want to use __getattr__ for lazy loading still can do this by importing submodules.
The main two use cases I know of for this and PEP 549 are lazy imports of submodules, and deprecating attributes.
Yes, lazy loading seems to be a popular idea :-) I will add the simple recipe by Inada to the PEP since it will already work.
I still think the better way to solve the custom dir() would be to change the module __dir__ method to check if __all__ is defined and use it to generate the result if it exists. This seems like a logical enhancement to me, and I'm planning on writing a patch to implement this. Whether it would be accepted is still an open issue though.
This seems a reasonable rule to me, I can also make this patch if you will not have time.
@Guido What do you think about the above idea?
Python-ideas mailing list Pythonemail@example.com https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/