From 51b25dc0aa8b9b935659777ad8c4e137477d6fc2 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Sun, 17 May 2026 11:26:29 -0700 Subject: [PATCH] fix: replace assert with proper exception in python_build_standalone (#2859) Assert statements are skipped under python -O, making them unsuitable for runtime validation. Replace assert with an explicit check that raises PythonBuildStandaloneError if the target directory already exists. Assisted-by: OpenCode:glm-5 --- cibuildwheel/util/python_build_standalone.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cibuildwheel/util/python_build_standalone.py b/cibuildwheel/util/python_build_standalone.py index 24a23556..f8dca73c 100644 --- a/cibuildwheel/util/python_build_standalone.py +++ b/cibuildwheel/util/python_build_standalone.py @@ -175,7 +175,9 @@ def create_python_build_standalone_environment( ) python_base_dir = temp_dir / "pbs" - assert not python_base_dir.exists() + if python_base_dir.exists(): + msg = f"python-build-standalone directory already exists: {python_base_dir}" + raise PythonBuildStandaloneError(msg) extract_tar(archive_path, python_base_dir) return _find_python_executable(python_base_dir)