diff -r c108bc96aec6 Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py Fri Jun 01 22:48:32 2012 +1000 +++ b/Lib/importlib/_bootstrap.py Fri Jun 01 21:23:04 2012 +0100 @@ -578,7 +578,8 @@ """Concrete implementation of InspectLoader.is_package by checking if the path returned by get_filename has a filename of '__init__.py'.""" filename = _path_split(self.get_filename(fullname))[1] - return filename.rsplit('.', 1)[0] == '__init__' + return (filename.rsplit('.', 1)[0] == '__init__' and + fullname.rpartition('.')[2] != '__init__') def _bytes_from_bytecode(self, fullname, data, bytecode_path, source_stats): """Return the marshalled bytes from bytecode, verifying the magic diff -r c108bc96aec6 Lib/importlib/test/import_/test_packages.py --- a/Lib/importlib/test/import_/test_packages.py Fri Jun 01 22:48:32 2012 +1000 +++ b/Lib/importlib/test/import_/test_packages.py Fri Jun 01 21:23:04 2012 +0100 @@ -4,6 +4,8 @@ import unittest import importlib from test import support +import tempfile +import os class ParentModuleTests(unittest.TestCase): @@ -102,6 +104,28 @@ finally: support.unload(subname) + def test___init__(self): + # #14938: importing pkg.__init__ should create pkg as a package and + # pkg.__init__ as a module. + try: + tempdir = tempfile.mkdtemp() + pkgdir = os.path.join(tempdir, 'pkg') + os.mkdir(pkgdir) + with open(os.path.join(pkgdir, '__init__.py'), 'w') as f: + f.write('') + + with util.import_state(path=[tempdir], meta_path=sys.meta_path, + path_hooks=sys.path_hooks): + with util.uncache('pkg', 'pkg.__util__'): + import_util.import_('pkg.__init__') + self.assertTrue('pkg' in sys.modules) + self.assertTrue('pkg.__init__' in sys.modules) + init = sys.modules['pkg.__init__'] + self.assertEqual(init.__package__, 'pkg') + self.assertFalse(hasattr(init, '__path__')) + finally: + support.rmtree(tempdir) + def test_main(): from test.support import run_unittest diff -r c108bc96aec6 Python/importlib.h Binary file Python/importlib.h has changed