[Python-Dev] Empty directory is a namespace?

Antoine Pitrou solipsis at pitrou.net
Sun Jun 24 19:46:15 CEST 2012


On Sun, 24 Jun 2012 13:44:52 -0400
PJ Eby <pje at telecommunity.com> wrote:
> On Sun, Jun 24, 2012 at 3:51 AM, "Martin v. Löwis" <martin at v.loewis.de>wrote:
> 
> > On 23.06.2012 17:58, Antoine Pitrou wrote:
> > > On Sat, 23 Jun 2012 17:55:24 +0200
> > > martin at v.loewis.de wrote:
> > >>> That's true. I would have hoped for it to be recognized only when
> > >>> there's at least one module or package inside, but it doesn't sound
> > >>> easy to check for (especially in the recursive namespace packages case
> > >>> - is that possible?).
> > >>
> > >> Yes - a directory becomes a namespace package by not having an
> > __init__.py,
> > >> so the "namespace package" case will likely become the default, and
> > people
> > >> will start removing the empty __init__.pys when they don't need to
> > support
> > >> 3.2- anymore.
> > >
> > > Have you tested the performance of namespace packages compared to
> > > normal packages?
> >
> > No, I haven't.
> >
> 
> It's probably not worthwhile; any performance cost increase due to looking
> at more sys.path entries should be offset by the speedup of any subsequent
> imports from later sys.path entries.
> 
> Or, to put it another way, almost all the extra I/O cost of namespace
> packages is paid only once, for the *first* namespace package imported.

And how about CPU cost?

> In short, it's not worth worrying about, and definitely nothing that
> should cause people to spread an idea that __init__.py somehow speeds
> things up.

The best way to avoid people spreading that idea would be to show hard
measurements.

Regards

Antoine.


More information about the Python-Dev mailing list