Skip to content

Commit 5ecedbd

Browse files
authored
gh-106789: avoid importing pprint from sysconfig (#106790)
1 parent 7aa89e5 commit 5ecedbd

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

Lib/opcode.py

+7-19
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,14 @@
66

77
__all__ = ["cmp_op", "hasarg", "hasconst", "hasname", "hasjrel", "hasjabs",
88
"haslocal", "hascompare", "hasfree", "hasexc", "opname", "opmap",
9-
"HAVE_ARGUMENT", "EXTENDED_ARG"]
10-
11-
# It's a chicken-and-egg I'm afraid:
12-
# We're imported before _opcode's made.
13-
# With exception unheeded
14-
# (stack_effect is not needed)
15-
# Both our chickens and eggs are allayed.
16-
# --Larry Hastings, 2013/11/23
17-
18-
try:
19-
from _opcode import stack_effect
20-
__all__.append('stack_effect')
21-
except ImportError:
22-
pass
23-
24-
# _opcode_metadata may not be ready during early stages of the build
25-
try:
9+
"stack_effect", "HAVE_ARGUMENT", "EXTENDED_ARG"]
10+
11+
from _opcode import stack_effect
12+
13+
import sys
14+
# The build uses older versions of Python which do not have _opcode_metadata
15+
if sys.version_info[:2] >= (3, 13):
2616
from _opcode_metadata import _specializations, _specialized_instructions
27-
except ModuleNotFoundError:
28-
pass
2917

3018
cmp_op = ('<', '<=', '==', '!=', '>', '>=')
3119

Lib/sysconfig.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,14 @@ def _get_sysconfigdata_name():
465465
f'_sysconfigdata_{sys.abiflags}_{sys.platform}_{multiarch}',
466466
)
467467

468+
def _print_config_dict(d, stream):
469+
print ("{", file=stream)
470+
for k, v in sorted(d.items()):
471+
print(f" {k!r}: {v!r},", file=stream)
472+
print ("}", file=stream)
468473

469474
def _generate_posix_vars():
470475
"""Generate the Python module containing build-time variables."""
471-
import pprint
472476
vars = {}
473477
# load the installed Makefile:
474478
makefile = get_makefile_filename()
@@ -523,7 +527,7 @@ def _generate_posix_vars():
523527
f.write('# system configuration generated and used by'
524528
' the sysconfig module\n')
525529
f.write('build_time_vars = ')
526-
pprint.pprint(vars, stream=f)
530+
_print_config_dict(vars, stream=f)
527531

528532
# Create file used for sys.path fixup -- see Modules/getpath.c
529533
with open('pybuilddir.txt', 'w', encoding='utf8') as f:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove import of :mod:``pprint`` from :mod:``sysconfig``.

0 commit comments

Comments
 (0)