On Fri, May 6, 2011 at 2:12 PM, Ethan Furman <ethan@stoneleaf.us> wrote:
Brendan Moloney wrote:
dag.odenhall@gmail.com wrote:
I like this idea, except it's inconsistent with from-import-star, the latter which does *not* get you sub-packages or modules.
Georg Brandl [g.brandl@gmx.net] wrote:
And that's for a reason: it's not easy (I think it's even impossible, because for example individual submodules can change __path__) to determine all importable submodules of a package.
So ``import pkg.*`` would not have any behavior other than ``import
pkg``.
When I said all _public_ sub-packages and modules I was referring to those
listed in the __all__ attribute of 'pkg'. Thus it would behave in the exact same way as from-import-star except you don't pollute the current namespace.
I'm not catching the vision -- could you put together a short example that would illustrate?
He's saying that the package would be imported like normal. Then all "public" sub-modules of the package would automatically imported and bound to the namespace of the object that resulted from the import of the package. The trickery is that __all__ in the __init__.py would change meaning somewhat, and, do you bind the submodules into the package's module object or something else? If you have a list of the submodules you want imported then you can already accomplish this: import parent for mod in parent.__all_submodules__: __import__("parent.{}".format(mod)) Of course, this does not bind the submodules to the namespace of the package module, but I suppose you could try that with one more step. I am not sure of the specific import mechanism with regards to name binding, but that would seem to be a conflict with the way imported names for submodules are bound. -eric ~Ethan~
_______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas