8000 bpo-42955: Rename module_names to sys.stdlib_module_names (GH-24332) · python/cpython@9852cb3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9852cb3

Browse files
authored
bpo-42955: Rename module_names to sys.stdlib_module_names (GH-24332)
* Rename _Py_module_names to _Py_stdlib_module_names. * Rename Python/module_names.h to Python/stdlib_module_names.h.
1 parent 501d4a5 commit 9852cb3

File tree

15 files changed

+61
-60
lines changed

15 files changed

+61
-60
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
# Build Python with the libpython dynamic library
6464
./configure --with-pydebug --enable-shared
6565
make -j4 regen-all
66-
make regen-module-names
66+
make regen-stdlib-module-names
6767
- name: Check for changes
6868
run: |
6969
changes=$(git status --porcelain)

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ before_script:
172172
- eval "$(pyenv init -)"
173173
- pyenv global 3.8
174174
- PYTHON_FOR_REGEN=python3.8 make -j4 regen-all
175-
- make regen-module-names
175+
- make regen-stdlib-module-names
176176
- changes=`git status --porcelain`
177177
- |
178178
# Check for changes in regenerated files

Doc/library/sys.rst

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ always available.
157157
Python interpreter. (This information is not available in any other way ---
158158
``modules.keys()`` only lists the imported modules.)
159159

160-
See also the :attr:`sys.module_names` list.
160+
See also the :attr:`sys.stdlib_module_names` list.
161161

162162

163163
.. function:: call_tracing(func, args)
@@ -1062,24 +1062,6 @@ always available.
10621062
This is still called as a fallback if a :data:`meta_path` entry doesn't
10631063
have a :meth:`~importlib.abc.MetaPathFinder.find_spec` method.
10641064

1065-
.. data:: module_names
1066-
1067-
A frozenset of strings containing the names of standard library modules.
1068-
1069-
It is the same on all platforms. Modules which are not available on
1070-
some platforms and modules disabled at Python build are also listed.
1071-
All module kinds are listed: pure Python, built-in, frozen and extension
1072-
modules. Test modules are excluded.
1073-
1074-
For packages, only sub-packages are listed, not sub-modules. For example,
1075-
``concurrent`` package and ``concurrent.futures`` sub-package are listed,
1076-
but not ``concurrent.futures.base`` sub-module.
1077-
1078-
See also the :attr:`sys.builtin_module_names` list.
1079-
1080-
.. versionadded:: 3.10
1081-
1082-
10831065
.. data:: modules
10841066

10851067
This is a dictionary that maps module names to modules which have already been
@@ -1584,6 +1566,24 @@ always available.
15841566
to a console and Python apps started with :program:`pythonw`.
15851567

15861568

1569+
.. data:: stdlib_module_names
1570+
1571+
A frozenset of strings containing the names of standard library modules.
1572+
1573+
It is the same on all platforms. Modules which are not available on
1574+
some platforms and modules disabled at Python build are also listed.
1575+
All module kinds are listed: pure Python, built-in, frozen and extension
1576+
modules. Test modules are excluded.
1577+
1578+
For packages, only sub-packages are listed, not sub-modules. For example,
1579+
``concurrent`` package and ``concurrent.futures`` sub-package are listed,
1580+
but not ``concurrent.futures.base`` sub-module.
1581+
1582+
See also the :attr:`sys.builtin_module_names` list.
1583+
1584+
.. versionadded:: 3.10
1585+
1586+
15871587
.. data:: thread_info
15881588

15891589
A :term:`named tuple` holding information about the thread

Doc/whatsnew/3.10.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ Add :data:`sys.orig_argv` attribute: the list of the original command line
396396
arguments passed to the Python executable.
397397
(Contributed by Victor Stinner in :issue:`23427`.)
398398
399-
Add :data:`sys.module_names`, containing the list of the standard library
399+
Add :data:`sys.stdlib_module_names`, containing the list of the standard library
400400
module names.
401401
(Contributed by Victor Stinner in :issue:`42955`.)
402402

Lib/test/test_capi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ def test_fatal_error(self):
581581
not_expected = ('_testcapi',)
582582
code = textwrap.dedent('''
583583
import _testcapi, sys
584-
sys.module_names = frozenset({"_testcapi"})
584+
sys.stdlib_module_names = frozenset({"_testcapi"})
585585
_testcapi.fatal_error(b"MESSAGE")
586586
''')
587587
self.check_fatal_error(code, expected)

Lib/test/test_faulthandler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def test_dump_ext_modules(self):
336336
import faulthandler
337337
import sys
338338
# Don't filter stdlib module names
339-
sys.module_names = frozenset()
339+
sys.stdlib_module_names = frozenset()
340340
faulthandler.enable()
341341
faulthandler._sigsegv()
342342
"""

Lib/test/test_sys.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -987,8 +987,8 @@ def test_orig_argv(self):
987987
proc)
988988

989989
def test_module_names(self):
990-
self.assertIsInstance(sys.module_names, frozenset)
991-
for name in sys.module_names:
990+
self.assertIsInstance(sys.stdlib_module_names, frozenset)
991+
for name in sys.stdlib_module_names:
992992
self.assertIsInstance(name, str)
993993

994994

Makefile.pre.in

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ regen-all: regen-opcode regen-opcode-targets regen-typeslots \
760760
regen-token regen-ast regen-keyword regen-importlib clinic \
761761
regen-pegen-metaparser regen-pegen
762762
@echo
763-
@echo "Note: make regen-module-names and autoconf should be run manually"
763+
@echo "Note: make regen-stdlib-module-names and autoconf should be run manually"
764764

765765
############################################################################
766766
# Special rules for object files
@@ -900,14 +900,14 @@ regen-keyword:
900900
$(srcdir)/Lib/keyword.py.new
901901
$(UPDATE_FILE) $(srcdir)/Lib/keyword.py $(srcdir)/Lib/keyword.py.new
902902

903-
.PHONY: regen-module-names
904-
regen-module-names: build_all
905-
# Regenerate Python/module_names.h
906-
# using Tools/scripts/generate_module_names.py
903+
.PHONY: regen-stdlib-module-names
904+
regen-stdlib-module-names: build_all
905+
# Regenerate Python/stdlib_module_names.h
906+
# using Tools/scripts/generate_stdlib_module_names.py
907907
$(RUNSHARED) ./$(BUILDPYTHON) \
908-
$(srcdir)/Tools/scripts/generate_module_names.py \
909-
> $(srcdir)/Python/module_names.h.new
910-
$(UPDATE_FILE) $(srcdir)/Python/module_names.h $(srcdir)/Python/module_names.h.new
908+
$(srcdir)/Tools/scripts/generate_stdlib_module_names.py \
909+
> $(srcdir)/Python/stdlib_module_names.h.new
910+
$(UPDATE_FILE) $(srcdir)/Python/stdlib_module_names.h $(srcdir)/Python/stdlib_module_names.h.new
911911

912912
Python/compile.o Python/symtable.o Python/ast_unparse.o Python/ast.o Python/future.o: $(srcdir)/Include/Python-ast.h
913913

@@ -1160,7 +1160,7 @@ PYTHON_HEADERS= \
11601160
$(srcdir)/Include/internal/pycore_warnings.h \
11611161
$(DTRACE_HEADERS) \
11621162
\
1163-
$(srcdir)/Python/module_names.h
1163+
$(srcdir)/Python/stdlib_module_names.h
11641164

11651165
$(LIBRARY_OBJS) $(MODOBJS) Programs/python.o: $(PYTHON_HEADERS)
11661166

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Add :data:`sys.module_names`, containing the list of the standard library
1+
Add :data:`sys.stdlib_module_names`, containing the list of the standard library
22
module names. Patch by Victor Stinner.

PCbuild/pythoncore.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@
291291
<ClInclude Include="..\Python\ceval_gil.h" />
292292
<ClInclude Include="..\Python\condvar.h" />
293293
<ClInclude Include="..\Python\importdl.h" />
294-
<ClInclude Include="..\Python\module_names.h" />
294+
<ClInclude Include="..\Python\stdlib_module_names.h" />
295295
<ClInclude Include="..\Python\thread_nt.h" />
296296
<ClInclude Include="..\Python\wordcode_helpers.h" />
297297
</ItemGroup>

PCbuild/pythoncore.vcxproj.filters

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@
360360
<ClInclude Include="..\Python\importdl.h">
361361
<Filter>Python</Filter>
362362
</ClInclude>
363-
<ClInclude Include="..\Python\module_names.h">
363+
<ClInclude Include="..\Python\stdlib_module_names.h">
364364
<Filter>Python</Filter>
365365
</ClInclude>
366366
<ClInclude Include="..\Python\thread_nt.h">

Python/pylifecycle.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,7 +2497,7 @@ fatal_error_exit(int status)
24972497

24982498

24992499
// Dump the list of extension modules of sys.modules, excluding stdlib modules
2500-
// (sys.module_names), into fd file descriptor.
2500+
// (sys.stdlib_module_names), into fd file descriptor.
25012501
//
25022502
// This function is called by a signal handler in faulthandler: avoid memory
25032503
// allocations and keep the implementation simple. For example, the list is not
@@ -2519,19 +2519,19 @@ _Py_DumpExtensionModules(int fd, PyInterpreterState *interp)
25192519
// Avoid PyDict_GetItemString() which calls PyUnicode_FromString(),
25202520
// memory cannot be allocated on the heap in a signal handler.
25212521
// Iterate on the dict instead.
2522-
PyObject *module_names = NULL;
2522+
PyObject *stdlib_module_names = NULL;
25232523
pos = 0;
25242524
while (PyDict_Next(interp->sysdict, &pos, &key, &value)) {
25252525
if (PyUnicode_Check(key)
2526-
&& PyUnicode_CompareWithASCIIString(key, "module_names") == 0) {
2527-
module_names = value;
2526+
&& PyUnicode_CompareWithASCIIString(key, "stdlib_module_names") == 0) {
2527+
stdlib_module_names = value;
25282528
break;
25292529
}
25302530
}
2531-
// If we failed to get sys.module_names or it's not a frozenset,
2531+
// If we failed to get sys.stdlib_module_names or it's not a frozenset,
25322532
// don't exclude stdlib modules.
2533-
if (module_names != NULL && !PyFrozenSet_Check(module_names)) {
2534-
module_names = NULL;
2533+
if (stdlib_module_names != NULL && !PyFrozenSet_Check(stdlib_module_names)) {
2534+
stdlib_module_names = NULL;
25352535
}
25362536

25372537
// List extensions
@@ -2547,13 +2547,13 @@ _Py_DumpExtensionModules(int fd, PyInterpreterState *interp)
25472547
}
25482548
// Use the module name from the sys.modules key,
25492549
// don't attempt to get the module object name.
2550-
if (module_names != NULL) {
2550+
if (stdlib_module_names != NULL) {
25512551
int is_stdlib_ext = 0;
25522552

2553-
Py_ssize_t i;
2553+
Py_ssize_t i = 0;
25542554
PyObject *item;
25552555
Py_hash_t hash;
2556-
for (i=0; _PySet_NextEntry(module_names, &i, &item, &hash); ) {
2556+
while (_PySet_NextEntry(stdlib_module_names, &i, &item, &hash)) {
25572557
if (PyUnicode_Check(item)
25582558
&& PyUnicode_Compare(key, item) == 0)
25592559
{

Python/module_names.h renamed to Python/stdlib_module_names.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// Auto-generated by Tools/scripts/generate_module_names.py.
2-
// List used to create sys.module_names.
1+
// Auto-generated by Tools/scripts/generate_stdlib_module_names.py.
2+
// List used to create sys.stdlib_module_names.
33

4-
static const char* _Py_module_names[] = {
4+
static const char* _Py_stdlib_module_names[] = {
55
"__future__",
66
"_abc",
77
"_aix_support",

Python/sysmodule.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Data members:
2929
#include "frameobject.h" // PyFrame_GetBack()
3030
#include "pydtrace.h"
3131
#include "osdefs.h" // DELIM
32-
#include "module_names.h" // _Py_module_names
32+
#include "stdlib_module_names.h" // _Py_stdlib_module_names
3333
#include <locale.h>
3434

3535
#ifdef MS_WINDOWS
@@ -2054,16 +2054,16 @@ list_builtin_module_names(void)
20542054

20552055

20562056
static PyObject *
2057-
list_module_names(void)
2057+
list_stdlib_module_names(void)
20582058
{
2059-
Py_ssize_t len = Py_ARRAY_LENGTH(_Py_module_names);
2059+
Py_ssize_t len = Py_ARRAY_LENGTH(_Py_stdlib_module_names);
20602060
PyObject *names = PyTuple_New(len);
20612061
if (names == NULL) {
20622062
return NULL;
20632063
}
20642064

20652065
for (Py_ssize_t i = 0; i < len; i++) {
2066-
PyObject *name = PyUnicode_FromString(_Py_module_names[i]);
2066+
PyObject *name = PyUnicode_FromString(_Py_stdlib_module_names[i]);
20672067
if (name == NULL) {
20682068
Py_DECREF(names);
20692069
return NULL;
@@ -2784,7 +2784,7 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)
27842784
SET_SYS("hash_info", get_hash_info(tstate));
27852785
SET_SYS("maxunicode", PyLong_FromLong(0x10FFFF));
27862786
SET_SYS("builtin_module_names", list_builtin_module_names());
2787-
SET_SYS("module_names", list_module_names());
2787+
SET_SYS("stdlib_module_names", list_stdlib_module_names());
27882788
#if PY_BIG_ENDIAN
27892789
SET_SYS_FROM_STRING("byteorder", "big");
27902790
#else

Tools/scripts/generate_module_names.py renamed to Tools/scripts/generate_stdlib_module_names.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This script lists the names of standard library modules
2-
# to update Python/module_names.h
2+
# to update Python/stdlib_mod_names.h
33
import os.path
44
import re
55
import subprocess
@@ -126,10 +126,11 @@ def list_modules():
126126

127127

128128
def write_modules(fp, names):
129-
print("// Auto-generated by Tools/scripts/generate_module_names.py.", file=fp)
130-
print("// List used to create sys.module_names.", file=fp)
129+
print("// Auto-generated by Tools/scripts/generate_stdlib_module_names.py.",
130+
file=fp)
131+
print("// List used to create sys.stdlib_module_names.", file=fp)
131132
print(file=fp)
132-
print("static const char* _Py_module_names[] = {", file=fp)
133+
print("static const char* _Py_stdlib_module_names[] = {", file=fp)
133134
for name in sorted(names):
134135
print(f'"{name}",', file=fp)
135136
print("};", file=fp)

0 commit comments

Comments
 (0)
0