python-imaging puts a "__init__" module in the top-level module namespace

Bug #31646 reported by Andrew Bennetts
8
Affects Status Importance Assigned to Milestone
python-imaging (Ubuntu)
Fix Released
Medium
Matthias Klose

Bug Description

PIL installs a PIL.pth file:

$ cat /usr/lib/python2.4/site-packages/PIL.pth
PIL

This means that the contents /usr/lib/python2.4/site-packages/PIL will be inserted into sys.path. However that directory is also a valid Python package (because it has a __init__.py) on the default search path (/usr/lib/python2.4/site-packages).

This is clearly buggy, because it means the same modules are importable twice, under different names (and python thinks they are different modules, and so they have different instances of globals):

>>> import Image
>>> PIL.Image
>>> PIL.Image is Image
False

Worse, this makes __init__ importable, which seems to confuse Python's traceback machinery sometimes, leading to tracebacks with weird lines like:

  File "/usr/lib/python2.4/site-packages/PIL/__init__.py", line 30, in ?

  File "/usr/lib/python2.4/site-packages/PIL/__init__.py", line 24, in ?

This can happen even to code that doesn't actually use PIL; it's mere presence breaks things.

Aside from all this, it's just ugly to add 75 names as top-level modules when one (just the "PIL" package) would do. Ideally the PIL.pth file would just be removed.

Revision history for this message
Andrew Bennetts (spiv) wrote :

I made a copy-and-paste bug with this snippet:

>>> import Image
>>> PIL.Image
>>> PIL.Image is Image
False

Clearly I meant:

>>> import Image
>>> import PIL.Image
>>> PIL.Image is Image
False

Revision history for this message
Matthias Klose (doko) wrote :

agreed, but probably not anymore for dapper.

Changed in python-imaging:
assignee: nobody → doko
status: Unconfirmed → Confirmed
Revision history for this message
Scott Kitterman (kitterman) wrote :

I have python-imaging installed in my Dapper box and confirmed that this was no longer the case.

Changed in python-imaging:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.