Skip to content

Commit 155577d

Browse files
authored
make regen-stdlib-module-names rejects test modules (#105921)
Make sure that sys.stdlib_module_names doesn't contain test modules.
1 parent cb388c9 commit 155577d

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

Tools/build/generate_stdlib_module_names.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@
4343
'xxsubtype',
4444
}
4545

46+
ALLOW_TEST_MODULES = {
47+
'doctest',
48+
'unittest',
49+
}
50+
51+
# Built-in modules
52+
def list_builtin_modules(names):
53+
names |= set(sys.builtin_module_names)
54+
55+
4656
# Pure Python modules (Lib/*.py)
4757
def list_python_modules(names):
4858
for filename in os.listdir(STDLIB_PATH):
@@ -93,7 +103,9 @@ def list_frozen(names):
93103

94104

95105
def list_modules():
96-
names = set(sys.builtin_module_names)
106+
names = set()
107+
108+
list_builtin_modules(names)
97109
list_modules_setup_extensions(names)
98110
list_packages(names)
99111
list_python_modules(names)
@@ -106,9 +118,12 @@ def list_modules():
106118
if package_name in IGNORE:
107119
names.discard(name)
108120

121+
# Sanity checks
109122
for name in names:
110123
if "." in name:
111-
raise Exception("sub-modules must not be listed")
124+
raise Exception(f"sub-modules must not be listed: {name}")
125+
if ("test" in name or "xx" in name) and name not in ALLOW_TEST_MODULES:
126+
raise Exception(f"test modules must not be listed: {name}")
112127

113128
return names
114129

0 commit comments

Comments
 (0)