This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Ronan.Lamy
Recipients Ronan.Lamy
Date 2012-05-28.18:52:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1338231140.08.0.643684499153.issue14938@psf.upfronthosting.co.za>
In-reply-to
Content
If an __init__.py file contains relative imports, doing 'import my_pkg.__init__' or calling __import__('my_pkg.__init__') creates duplicate versions of the relatively imported modules, which (I believe) causes cryptic errors in some cases (cf. the metaclass issue in http://code.google.com/p/sympy/issues/detail?id=3272 ).

More precisely, with my_pkg/__init__.py containing (see attachment for the full setup):

from .module1 import a
from my_pkg.module2 import b

I get:

Python 3.3.0a3+ (default:0685f51e9891, May 27 2012, 02:22:12) 
[GCC 4.6.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import my_pkg.__init__
>>> import sys
>>> sorted(name for name in sys.modules if name.startswith('my_'))
['my_pkg', 'my_pkg.__init__', 'my_pkg.__init__.module1', 'my_pkg.module1', 'my_pkg.module2']
>>> 

Note the bogus 'my_pkg.__init__.module1' entry. For reference, in Python 3.2, the last line is:

['my_pkg', 'my_pkg.__init__', 'my_pkg.module1', 'my_pkg.module2']


NB: calling __import__('my_pkg.__init__') might seem odd (I didn't actually expect it to work on any Python version), but doctest apparently relies on it to test __init__.py files.
History
Date User Action Args
2012-05-28 18:52:20Ronan.Lamysetrecipients: + Ronan.Lamy
2012-05-28 18:52:20Ronan.Lamysetmessageid: <1338231140.08.0.643684499153.issue14938@psf.upfronthosting.co.za>
2012-05-28 18:52:19Ronan.Lamylinkissue14938 messages
2012-05-28 18:52:19Ronan.Lamycreate