[Import-SIG] What if namespace imports weren't special?
Stephen Waterbury
waterbug at pangalactic.us
Mon Jul 11 05:07:34 CEST 2011
On 07/10/2011 10:34 PM, P.J. Eby wrote:
> I think one reason we're having trouble with naming and explaining this
> whole concept is that, really, the current Python import system is
> broken, compared to other languages.
That seems an important consideration, at least because of the
negative perception it presents to programmers coming from other
languages ...
> ... All packages *should* be namespace packages, pretty
> much. It's the *non* namespaceyness of Python's default packages that's
> broken, not the term. ;-)
Novel to a Python programmer, perhaps even "revolutionary",
but logical on the face of it.
> Actually... here's an interesting idea. Suppose that we define the rules
> so that any directory containing any file with an importable extension
> is a namespace package... *but*, if one of those directories contains an
> __init__ module, that directory will be placed first on the package
> __path__.
>
> If we did that, then there would be no need for any special flag files ...
I like losing the flag files -- nice!
> The only backward compatibility that this can break is that you can
> import things you couldn't import before. ...
... which seems like no breakage at all, really.
> In other words, the first subdirectory with an __init__ gets to head up
> the new package's __path__, but ALL matching subdirectories will make up
> the tail.
>
> The big advantage of this approach is that it doesn't require us to have
> a special name - it's just, "Enhanced Package Imports" or some such. No
> special marker files to name, either. Just, "hey, people want to put
> their package contents in more than one directory, and they don't always
> need an __init__.py."
>
> Thoughts, anyone?
I like it very much: it seems elegant and minimalist.
To put my comments in context, I am a non-implementor and non-guru,
but also a Python old-timer, who wants to use "partitioned packages"
and would like to see this done right. I.e., this is input from the
peanut gallery. ;)
Cheers,
Steve
More information about the Import-SIG
mailing list