From ca1e86f9d963dc298d9a486d5230b1b3a9f32245 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Wed, 19 Nov 2025 15:57:44 -0800 Subject: [PATCH 1/4] Simplify setting CLI options for WASI builds (GH-141769) This introduces a Wasmtime configuration file to get some CLI options out of the code for easier manipulation. It also allows for easier tweaking after the Makefile is generated. As well, cut back on the flexibility of specifying HOSTRUNNER for simpler code. The flexibility was never used and so it didn't make sense to keep it around. --- Tools/wasm/wasi/__main__.py | 33 ++++++++++++++++----------------- Tools/wasm/wasi/wasmtime.toml | 5 +++++ 2 files changed, 21 insertions(+), 17 deletions(-) create mode 100644 Tools/wasm/wasi/wasmtime.toml diff --git a/Tools/wasm/wasi/__main__.py b/Tools/wasm/wasi/__main__.py index 59ffd436258185..06903fd25abe44 100644 --- a/Tools/wasm/wasi/__main__.py +++ b/Tools/wasm/wasi/__main__.py @@ -16,7 +16,9 @@ import sysconfig import tempfile -CHECKOUT = pathlib.Path(__file__).parent.parent.parent.parent +HERE = pathlib.Path(__file__).parent + +CHECKOUT = HERE.parent.parent.parent assert (CHECKOUT / "configure").is_file(), ( "Please update the location of the file" ) @@ -304,9 +306,7 @@ def configure_wasi_python(context, working_dir): "specify via $WASI_SDK_PATH or --wasi-sdk" ) - config_site = os.fsdecode( - CHECKOUT / "Tools" / "wasm" / "wasi" / "config.site-wasm32-wasi" - ) + config_site = os.fsdecode(HERE / "config.site-wasm32-wasi") wasi_build_dir = working_dir.relative_to(CHECKOUT) @@ -324,10 +324,7 @@ def configure_wasi_python(context, working_dir): # Use PYTHONPATH to include sysconfig data which must be anchored to the # WASI guest's `/` directory. args = { - "GUEST_DIR": "/", - "HOST_DIR": CHECKOUT, - "ENV_VAR_NAME": "PYTHONPATH", - "ENV_VAR_VALUE": f"/{sysconfig_data_dir}", + "PYTHONPATH": f"/{sysconfig_data_dir}", "PYTHON_WASM": working_dir / "python.wasm", } # Check dynamically for wasmtime in case it was specified manually via @@ -417,16 +414,18 @@ def main(): default_wasi_sdk = find_wasi_sdk() default_host_runner = ( f"{WASMTIME_HOST_RUNNER_VAR} run " - # Make sure the stack size will work for a pydebug - # build. - # Use 32 MiB stack. - "--wasm max-wasm-stack=33554432 " - # Enable thread support; causes use of preview1. - # "--wasm threads=y --wasi threads=y " + # For setting PYTHONPATH to the sysconfig data directory. + "--env PYTHONPATH={PYTHONPATH} " # Map the checkout to / to load the stdlib from /Lib. - "--dir {HOST_DIR}::{GUEST_DIR} " - # Set PYTHONPATH to the sysconfig data. - "--env {ENV_VAR_NAME}={ENV_VAR_VALUE}" + f"--dir {os.fsdecode(CHECKOUT)}::/ " + # Flags involving --optimize, --codegen, --debug, --wasm, and --wasi can be kept + # in a config file. + # We are using such a file to act as defaults in case a user wants to override + # only some of the settings themselves, make it easy to modify settings + # post-build so that they immediately apply to the Makefile instead of having to + # regenerate it, and allow for easy copying of the settings for anyone else who + # may want to use them. + f"--config {os.fsdecode(HERE / 'wasmtime.toml')}" ) default_logdir = pathlib.Path(tempfile.gettempdir()) diff --git a/Tools/wasm/wasi/wasmtime.toml b/Tools/wasm/wasi/wasmtime.toml new file mode 100644 index 00000000000000..5a45e8c3db94a6 --- /dev/null +++ b/Tools/wasm/wasi/wasmtime.toml @@ -0,0 +1,5 @@ +# https://docs.wasmtime.dev/cli-options.html#cli-options-using-toml-file + +[wasm] +# 32 MiB; big enough for the test suite to pass under a debug build. +max-wasm-stack = 33_554_432 From e5adaafc52060ece7232ee074a7133b78fe01f9e Mon Sep 17 00:00:00 2001 From: Guo Ci Date: Wed, 19 Nov 2025 21:39:54 -0500 Subject: [PATCH 2/4] [Docs] Fix typo in bdb: `is_skipped_line` to `is_skipped_module` (#141771) --- Doc/library/bdb.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/bdb.rst b/Doc/library/bdb.rst index c7a3e0c596b9d0..a3c6da7a6d686b 100644 --- a/Doc/library/bdb.rst +++ b/Doc/library/bdb.rst @@ -236,7 +236,7 @@ The :mod:`bdb` module also defines two classes: Normally derived classes don't override the following methods, but they may if they want to redefine the definition of stopping and breakpoints. - .. method:: is_skipped_line(module_name) + .. method:: is_skipped_module(module_name) Return ``True`` if *module_name* matches any skip pattern. From bc9b9d47f9d649661c9c0c3e042ad9e559b9c81e Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Wed, 19 Nov 2025 18:41:25 -0800 Subject: [PATCH 3/4] gh-141615: Check stdin instead of stdout for use_rawinput in pdb (#141616) --- Lib/pdb.py | 4 ++-- Lib/test/test_pdb.py | 13 +++++++++++++ .../2025-11-16-06-08-46.gh-issue-141615.--6EK3.rst | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2025-11-16-06-08-46.gh-issue-141615.--6EK3.rst diff --git a/Lib/pdb.py b/Lib/pdb.py index 76bb28d7396452..8e9502cb9e6bfb 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -346,8 +346,8 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None, bdb.Bdb.__init__(self, skip=skip, backend=backend if backend else get_default_backend()) cmd.Cmd.__init__(self, completekey, stdin, stdout) sys.audit("pdb.Pdb") - if stdout: - self.use_rawinput = 0 + if stdin: + self.use_rawinput = False self.prompt = '(Pdb) ' self.aliases = {} self.displaying = {} diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 9d89008756a1d3..418ea79cdd22c3 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -4744,6 +4744,19 @@ def test_readline_not_imported(self): self.assertNotIn("readline imported", stdout) self.assertEqual(stderr, "") + def test_alternate_stdin(self): + script = textwrap.dedent(""" + import pdb + import io + + input_data = io.StringIO("p 40 + 2\\nc\\n") + pdb.Pdb(stdin=input_data).set_trace() + """) + commands = "" + stdout, stderr = self._run_script(script, commands) + self.assertIn("42", stdout) + self.assertEqual(stderr, "") + @support.force_colorized_test_class class PdbTestColorize(unittest.TestCase): diff --git a/Misc/NEWS.d/next/Library/2025-11-16-06-08-46.gh-issue-141615.--6EK3.rst b/Misc/NEWS.d/next/Library/2025-11-16-06-08-46.gh-issue-141615.--6EK3.rst new file mode 100644 index 00000000000000..bb54e68398722f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-11-16-06-08-46.gh-issue-141615.--6EK3.rst @@ -0,0 +1 @@ +Check ``stdin`` instead of ``stdout`` for ``use_rawinput`` in :mod:`pdb`. From a35c683da55e77c96828fd0421640787337cfc64 Mon Sep 17 00:00:00 2001 From: dr-carlos <77367421+dr-carlos@users.noreply.github.com> Date: Thu, 20 Nov 2025 14:38:08 +1030 Subject: [PATCH 4/4] gh-141489: Simplify closure/freevar iteration in `annotationlib._build_closure()` (#141490) --- Lib/annotationlib.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Lib/annotationlib.py b/Lib/annotationlib.py index 33907b1fc2a53a..a5788cdbfae3f5 100644 --- a/Lib/annotationlib.py +++ b/Lib/annotationlib.py @@ -844,14 +844,9 @@ def call_annotate_function(annotate, format, *, owner=None, _is_evaluate=False): def _build_closure(annotate, owner, is_class, stringifier_dict, *, allow_evaluation): if not annotate.__closure__: return None, None - freevars = annotate.__code__.co_freevars new_closure = [] cell_dict = {} - for i, cell in enumerate(annotate.__closure__): - if i < len(freevars): - name = freevars[i] - else: - name = "__cell__" + for name, cell in zip(annotate.__code__.co_freevars, annotate.__closure__, strict=True): cell_dict[name] = cell new_cell = None if allow_evaluation: