[Python-checkins] bpo-42955: Remove sub-packages from sys.stdlib_module_names (GH-24353)

vstinner webhook-mailer at python.org
Wed Jan 27 18:03:31 EST 2021


https://github.com/python/cpython/commit/64fc105b2d2faaeadd1026d2417b83915af6622f
commit: 64fc105b2d2faaeadd1026d2417b83915af6622f
branch: master
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2021-01-28T00:03:23+01:00
summary:

bpo-42955: Remove sub-packages from sys.stdlib_module_names (GH-24353)

files:
M Doc/library/sys.rst
M Python/stdlib_module_names.h
M Tools/scripts/generate_stdlib_module_names.py

diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst
index 0219ae8ceb65f..80b30d01f91aa 100644
--- a/Doc/library/sys.rst
+++ b/Doc/library/sys.rst
@@ -1575,9 +1575,10 @@ always available.
    All module kinds are listed: pure Python, built-in, frozen and extension
    modules. Test modules are excluded.
 
-   For packages, only sub-packages are listed, not sub-modules. For example,
-   ``concurrent`` package and ``concurrent.futures`` sub-package are listed,
-   but not ``concurrent.futures.base`` sub-module.
+   For packages, only the main package is listed: sub-packages and sub-modules
+   are not listed. For example, the ``email`` package is listed, but the
+   ``email.mime`` sub-package and the ``email.message`` sub-module are not
+   listed.
 
    See also the :attr:`sys.builtin_module_names` list.
 
diff --git a/Python/stdlib_module_names.h b/Python/stdlib_module_names.h
index 8c430821d64b8..01aa6753e4201 100644
--- a/Python/stdlib_module_names.h
+++ b/Python/stdlib_module_names.h
@@ -117,7 +117,6 @@ static const char* _Py_stdlib_module_names[] = {
 "colorsys",
 "compileall",
 "concurrent",
-"concurrent.futures",
 "configparser",
 "contextlib",
 "contextvars",
@@ -126,7 +125,6 @@ static const char* _Py_stdlib_module_names[] = {
 "crypt",
 "csv",
 "ctypes",
-"ctypes.macholib",
 "curses",
 "dataclasses",
 "datetime",
@@ -135,13 +133,10 @@ static const char* _Py_stdlib_module_names[] = {
 "difflib",
 "dis",
 "distutils",
-"distutils.command",
 "doctest",
 "email",
-"email.mime",
 "encodings",
 "ensurepip",
-"ensurepip._bundled",
 "enum",
 "errno",
 "faulthandler",
@@ -178,8 +173,6 @@ static const char* _Py_stdlib_module_names[] = {
 "json",
 "keyword",
 "lib2to3",
-"lib2to3.fixes",
-"lib2to3.pgen2",
 "linecache",
 "locale",
 "logging",
@@ -194,7 +187,6 @@ static const char* _Py_stdlib_module_names[] = {
 "msilib",
 "msvcrt",
 "multiprocessing",
-"multiprocessing.dummy",
 "netrc",
 "nis",
 "nntplib",
@@ -304,10 +296,6 @@ static const char* _Py_stdlib_module_names[] = {
 "wsgiref",
 "xdrlib",
 "xml",
-"xml.dom",
-"xml.etree",
-"xml.parsers",
-"xml.sax",
 "xmlrpc",
 "zipapp",
 "zipfile",
diff --git a/Tools/scripts/generate_stdlib_module_names.py b/Tools/scripts/generate_stdlib_module_names.py
index 02647691fc4d6..379b262e822db 100644
--- a/Tools/scripts/generate_stdlib_module_names.py
+++ b/Tools/scripts/generate_stdlib_module_names.py
@@ -57,29 +57,17 @@ def list_python_modules(names):
         names.add(name)
 
 
-def _list_sub_packages(path, names, parent=None):
-    for name in os.listdir(path):
+# Packages in Lib/
+def list_packages(names):
+    for name in os.listdir(STDLIB_PATH):
         if name in IGNORE:
             continue
-        package_path = os.path.join(path, name)
+        package_path = os.path.join(STDLIB_PATH, name)
         if not os.path.isdir(package_path):
             continue
-        if not any(package_file.endswith(".py")
-                   for package_file in os.listdir(package_path)):
-            continue
-        if parent:
-            qualname = f"{parent}.{name}"
-        else:
-            qualname = name
-        if qualname in IGNORE:
-            continue
-        names.add(qualname)
-        _list_sub_packages(package_path, names, qualname)
-
-
-# Packages and sub-packages
-def list_packages(names):
-    _list_sub_packages(STDLIB_PATH, names)
+        if any(package_file.endswith(".py")
+               for package_file in os.listdir(package_path)):
+            names.add(name)
 
 
 # Extension modules built by setup.py



More information about the Python-checkins mailing list