[Import-SIG] New draft revision for PEP 382

Nick Coghlan ncoghlan at gmail.com
Sat Jul 9 11:07:14 CEST 2011

On Sat, Jul 9, 2011 at 6:42 PM, Eric Snow <ericsnowcurrently at gmail.com> wrote:
> Correct me if I'm wrong, but I have understood that for namespace
> packages in the PEP, the directory name does not have to be the
> package name.

No, if the directory name doesn't match, the interpreter won't even
check it for __init__.py or .ns files, so there's no way for it to
satisfy an import request (remember, the .ns files don't live directly
in directories on sys.path - they live in *subdirectories* of those

> Back to namespace subpackages, it's unclear how they should work.
> Either a namespace package is at the top level of a sys.path entry, or
> its a module of a parent package, namespace or otherwise.  The
> top-level case is pretty clear.  However, the subpackage case is not.
> I don't see namespace subpackages as being too practical with
> non-namespace parent packages, but I'm probably missing something.
> In the case that a namespace subpackage has a namespace package
> parent, how would that look?  In the email to Barry you gave an
> example that covered this a little, but it's still pretty unclear.  In
> any case, I think more examples with namespace subpackages would be
> helpful.  Or maybe namespace subpackages are a corner case that
> doesn't deserve the keystrokes I've given it.  ;)

The subpackage import is just a scaled down version of top-level
imports, with pkg.__path__ taking on the role of sys.path.

Now, in normal circumstances, it's a pretty degenerate case with
pkg.__path__ containing only a single directory (the directory where
the __init__.py file lives).

namespace packages (either created via PEP 382 or one of the existing
namespace package systems) are one way to get multiple entries into
pkg.__path__, but not the only way (__init__.py can do it, as can
other application code).

Regardless of how it happens, the process of handling it under PEP 382
is the same as it is for top-level imports - once the import machinery
sees a .ns file in a directory that matches the current import inside
that package, it then scans the rest of the pkg.__path__ entries
looking for more directories that also contain .ns files, adding all
those directories to pkg.subpkg.__path__


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

More information about the Import-SIG mailing list