[Python-ideas] Allow 'import star' with namespaces

Paul Moore p.f.moore at gmail.com
Sat May 7 10:58:56 CEST 2011


On 7 May 2011 01:38, Guido van Rossum <guido at python.org> wrote:
> The point is that the pkg should use __all__ to declare what submodules
> exist. That's what it was invented for!

Hmm, OK. I missed that. But how would that work?

p1/__init__.py:

__all__ = ['p2', 'foo']
def foo(): print "p1.foo"

p1/p2/__init__.py:

__all__ = ['foo']
def foo(): print "p1.foo"

If I import p1, p1.__all__ shows me that p2 and foo are public. p1.foo
exists and I can tell it's not a module. p1.p2 doesn't exist in the p1
namespace at the moment, so how do I tell that I need to import it?
Just assume all nonexistent names are subpackages, and import them?
That doesn't seem like a very robust approach.

A proof of concept in the form of a Python implementation (as a
function) would help me understand, I guess. (But I still doubt that
even if it's implementable, the feature is much practical use...)

Paul.



More information about the Python-ideas mailing list