diff -r adb6b029b102 Lib/__xxpackage__/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/__xxpackage__/__init__.py Sat Mar 26 23:18:09 2016 +0300 @@ -0,0 +1,2 @@ +# This file exists as a helper for the test.test_importlib.builtin.test_finder module. + diff -r adb6b029b102 Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py Wed Mar 09 15:02:31 2016 +0100 +++ b/Lib/importlib/_bootstrap.py Sat Mar 26 23:18:09 2016 +0300 @@ -715,8 +715,6 @@ @classmethod def find_spec(cls, fullname, path=None, target=None): - if path is not None: - return None if _imp.is_builtin(fullname): return spec_from_loader(fullname, cls, origin='built-in') else: @@ -726,8 +724,6 @@ def find_module(cls, fullname, path=None): """Find the built-in module. - If 'path' is ever specified then the search is considered a failure. - This method is deprecated. Use find_spec() instead. """ diff -r adb6b029b102 Lib/test/test_importlib/builtin/test_finder.py --- a/Lib/test/test_importlib/builtin/test_finder.py Wed Mar 09 15:02:31 2016 +0100 +++ b/Lib/test/test_importlib/builtin/test_finder.py Sat Mar 26 23:18:09 2016 +0300 @@ -20,16 +20,12 @@ self.assertEqual(found.origin, 'built-in') # Built-in modules cannot be a package. - test_package = None + test_package = test_package_in_package = test_package_over_module = None - # Built-in modules cannobt be in a package. - test_module_in_package = None + def test_module_in_package(self): + spec = self.machinery.BuiltinImporter.find_spec('__xxpackage__.xx', ['__xxpackage__']) + self.assertIsNotNone(spec) - # Built-in modules cannot be a package. - test_package_in_package = None - - # Built-in modules cannot be a package. - test_package_over_module = None def test_failure(self): name = 'importlib' @@ -37,13 +33,6 @@ spec = self.machinery.BuiltinImporter.find_spec(name) self.assertIsNone(spec) - def test_ignore_path(self): - # The value for 'path' should always trigger a failed import. - with util.uncache(util.BUILTINS.good_name): - spec = self.machinery.BuiltinImporter.find_spec(util.BUILTINS.good_name, - ['pkg']) - self.assertIsNone(spec) - (Frozen_FindSpecTests, Source_FindSpecTests @@ -65,21 +54,16 @@ # Built-in modules cannot be a package. test_package = test_package_in_package = test_package_over_module = None - # Built-in modules cannot be in a package. - test_module_in_package = None + def test_module_in_package(self): + loader = self.machinery.BuiltinImporter.find_module('__xxpackage__.xx', ['__xxpackage__']) + self.assertTrue(hasattr(loader, 'load_module')) + def test_failure(self): assert 'importlib' not in sys.builtin_module_names loader = self.machinery.BuiltinImporter.find_module('importlib') self.assertIsNone(loader) - def test_ignore_path(self): - # The value for 'path' should always trigger a failed import. - with util.uncache(util.BUILTINS.good_name): - loader = self.machinery.BuiltinImporter.find_module(util.BUILTINS.good_name, - ['pkg']) - self.assertIsNone(loader) - (Frozen_FinderTests, Source_FinderTests diff -r adb6b029b102 Modules/Setup.dist --- a/Modules/Setup.dist Wed Mar 09 15:02:31 2016 +0100 +++ b/Modules/Setup.dist Sat Mar 26 23:18:09 2016 +0300 @@ -386,7 +386,7 @@ #_codecs_tw cjkcodecs/_codecs_tw.c # Example -- included for reference only: -# xx xxmodule.c +__xxpackage__.xx xxmodule.c # Another example -- the 'xxsubtype' module shows C-level subtyping in action xxsubtype xxsubtype.c diff -r adb6b029b102 Modules/makesetup --- a/Modules/makesetup Wed Mar 09 15:02:31 2016 +0100 +++ b/Modules/makesetup Sat Mar 26 23:18:09 2016 +0300 @@ -178,8 +178,6 @@ *.cpp) srcs="$srcs $arg";; \$*) libs="$libs $arg" cpps="$cpps $arg";; - *.*) echo 1>&2 "bad word $arg in $line" - exit 1;; -u) skip=libs; libs="$libs -u";; [a-zA-Z_]*) mods="$mods $arg";; *) echo 1>&2 "bad word $arg in $line" @@ -256,8 +254,13 @@ INITBITS= for mod in $MODS do + # split at the last dot to get mod name + fullname=$mod + mod=`echo $mod | sed -re "s/(.*)\.(.*)/\2/"` + # if there was no dot, the mod is the full name + [ $mod == "" ] && mod=$fullname EXTDECLS="${EXTDECLS}extern PyObject* PyInit_$mod(void);$NL" - INITBITS="${INITBITS} {\"$mod\", PyInit_$mod},$NL" + INITBITS="${INITBITS} {\"$fullname\", PyInit_$mod},$NL" done diff -r adb6b029b102 Python/import.c --- a/Python/import.c Wed Mar 09 15:02:31 2016 +0100 +++ b/Python/import.c Sat Mar 26 23:18:09 2016 +0300 @@ -1045,6 +1045,7 @@ PyObject *name; char *namestr; PyObject *mod; + char *oldcontext; name = PyObject_GetAttrString(spec, "name"); if (name == NULL) { @@ -1073,7 +1074,12 @@ Py_DECREF(name); return mod; } + + oldcontext = _Py_PackageContext; + _Py_PackageContext = PyUnicode_AsUTF8(name); mod = (*p->initfunc)(); + _Py_PackageContext = oldcontext; + if (mod == NULL) { Py_DECREF(name); return NULL;