[Import-SIG] PEP 395 (Module aliasing) and the namespace PEPs

Nick Coghlan ncoghlan at gmail.com
Thu Nov 17 02:52:32 CET 2011


On Thu, Nov 17, 2011 at 10:10 AM, PJ Eby <pje at telecommunity.com> wrote:
> On Wed, Nov 16, 2011 at 5:41 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>>
>> If the package directory markers are explicit (as they are now and as
>> they are in PEP 382), then PEP 395 isn't guessing - the mapping from
>> the filesystem layout to the Python module namespace is completely
>> unambiguous, since the directory added as sys.path[0] will always be
>> the first parent directory that isn't marked as a package directory:
>
> Sorry, but that's *still guessing*.  Random extraneous __init__.py and
> subdirectories on sys.path can screw you over.  For example, if I have a
> stray __init__.py in site-packages, does that mean that every module there
> is a submodule of a package called 'site-packages'?

Yes. (although in that case, you'd error out, since the package name
isn't valid).

Errors should never pass silently - ignoring such a screw-up in their
filesystem layout is letting an error pass silently and will most
likely cause obscure problems further down the road.

> Sure, you could fix that problem by ignoring names with a '-', but that's
> just an illustration.  The __init__.py idea was a very good attempt at
> solving the problem, but even in today's Python, it's still ambiguous and we
> should refuse to guess.  (Because it will result in weird behavior that's
> *much* harder to debug.)
> Import aliasing detection and relative import errors, on the other hand,
> don't rely on guessing.

Umm, if people screw up their filesystem layouts and *lie* to the
interpreter about whether or not something is a package, how is that
our fault? "Oh, they told me something, but they might not mean it, so
I'll choose to ignore the information they've given me" is the part
that sounds like guessing to me.

If we error *immediately*, telling them what's wrong with their
filesystem, that's the *opposite* of guessing.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Import-SIG mailing list