[Python-checkins] [3.11] GH-102700: allow built-in modules to be submodules (GH-103162) (GH-103322)

brettcannon webhook-mailer at python.org
Thu Apr 6 19:06:10 EDT 2023


https://github.com/python/cpython/commit/123680f9aa44d3374ba86b63b4ea0c394e13dfe5
commit: 123680f9aa44d3374ba86b63b4ea0c394e13dfe5
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: brettcannon <brett at python.org>
date: 2023-04-06T16:06:02-07:00
summary:

[3.11] GH-102700: allow built-in modules to be submodules (GH-103162) (GH-103322)

GH-102700: allow built-in modules to be submodules (GH-103162)
(cherry picked from commit 5d08c3ff7d89ca11556f18663a372f6c12435504)

Co-authored-by: Brett Cannon <brett at python.org>

files:
A Misc/NEWS.d/next/Core and Builtins/2023-04-01-00-46-31.gh-issue-102700.493NB4.rst
M Lib/importlib/_bootstrap.py
M Lib/test/test_importlib/builtin/test_finder.py

diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index afb95f4e1df8..ee93ebc3960c 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -747,8 +747,6 @@ def module_repr(module):
 
     @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=cls._ORIGIN)
         else:
diff --git a/Lib/test/test_importlib/builtin/test_finder.py b/Lib/test/test_importlib/builtin/test_finder.py
index a4869e07b9c0..81dc5a3699d9 100644
--- a/Lib/test/test_importlib/builtin/test_finder.py
+++ b/Lib/test/test_importlib/builtin/test_finder.py
@@ -37,13 +37,6 @@ def test_failure(self):
         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
@@ -77,16 +70,6 @@ def test_failure(self):
             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):
-            with warnings.catch_warnings():
-                warnings.simplefilter("ignore", DeprecationWarning)
-                loader = self.machinery.BuiltinImporter.find_module(
-                                                        util.BUILTINS.good_name,
-                                                        ['pkg'])
-            self.assertIsNone(loader)
-
 
 (Frozen_FinderTests,
  Source_FinderTests
diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-04-01-00-46-31.gh-issue-102700.493NB4.rst b/Misc/NEWS.d/next/Core and Builtins/2023-04-01-00-46-31.gh-issue-102700.493NB4.rst
new file mode 100644
index 000000000000..46951486e4f9
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2023-04-01-00-46-31.gh-issue-102700.493NB4.rst	
@@ -0,0 +1 @@
+Allow built-in modules to be submodules. This allows submodules to be statically linked into a CPython binary.



More information about the Python-checkins mailing list