[Import-SIG] PEP 382: Partial packages
pje at telecommunity.com
Tue Jul 12 01:26:41 CEST 2011
At 12:24 AM 7/12/2011 +0200, Martin v. Löwis wrote:
>So I don't see why the PHP include mechanism is related to "namespace
>packages" at all.
Because only in Python does a search for "foo/bar" (whatever the
separator) *stops* the path search when there is a match for
"foo/". In PHP, Perl, and Java, searching continues along the path
until the entire target is matched, regardless of whether the name
parts are separated by slashes (PHP), dots (Java), or double-colons (Perl).
That's why Python's behavior here is arguably a misfeature. In these
other languages, there is a distinction between an entity named "x"
and a *namespace* named "x::" (or "x/" or "x."), in their on-disk
For example, in Java, the class org.Foo is distinct from the
namespace org.Foo.* in on-disk representation, as you have
org/Foo.java (or .class) sitting outside the directory org/Foo/
(where any contents of org.Foo.* would be located.
Similarly in Perl, Foo.pm sits outside the Foo/ directory, thereby
distinguishing Foo and Foo::.
Python, however, in the case where both a Foo module and Foo package
exist, places the module *inside* the package.
If Python were following the model of these other languages, then
instead of using zope/__init__.py, we would place a zope.py in the
parent directory, and when importing zope.interface, we would search
the entire path for zope/ subdirectories containing an
interface.py... but we wouldn't look for interface/ directories
until/unless we tried to import zope.interface.foo.
More information about the Import-SIG