From 092449045693dee2394aa159426a2e0bd6b5c348 Mon Sep 17 00:00:00 2001 From: Dustin Ngo Date: Fri, 8 Aug 2025 19:45:13 -0400 Subject: [PATCH] fix: Use 3.9 compatible zip (#15177) ## Summary Uses a <3.10-compatible version of `zip` since the `strict` argument was [added in 3.10](https://docs.python.org/3.10/library/functions.html#zip) ## Test Plan I executed the `_matching_parents` function in a local 3.9 environment --------- Co-authored-by: Zanie Blue --- crates/uv/tests/it/python_module.rs | 32 +++++++++-------------------- python/uv/_find_uv.py | 6 ++++-- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/crates/uv/tests/it/python_module.rs b/crates/uv/tests/it/python_module.rs index a76fd81cd..91569db60 100644 --- a/crates/uv/tests/it/python_module.rs +++ b/crates/uv/tests/it/python_module.rs @@ -412,20 +412,14 @@ fn find_uv_bin_py38() { // We should find the binary in the virtual environment uv_snapshot!(context.filters(), context.python_command() .arg("-c") - .arg("import uv; print(uv.find_uv_bin())"), @r#" - success: false - exit_code: 1 + .arg("import uv; print(uv.find_uv_bin())"), @r" + success: true + exit_code: 0 ----- stdout ----- + [VENV]/[BIN]/uv ----- stderr ----- - Traceback (most recent call last): - File "", line 1, in - File "[SITE_PACKAGES]/uv/_find_uv.py", line 28, in find_uv_bin - _matching_parents(_module_path(), "lib/[PYTHON]*/site-packages/uv"), "bin" - File "[SITE_PACKAGES]/uv/_find_uv.py", line 79, in _matching_parents - for part, match_part in zip( - TypeError: zip() takes no keyword arguments - "# + " ); } @@ -458,20 +452,14 @@ fn find_uv_bin_py39() { // We should find the binary in the virtual environment uv_snapshot!(context.filters(), context.python_command() .arg("-c") - .arg("import uv; print(uv.find_uv_bin())"), @r#" - success: false - exit_code: 1 + .arg("import uv; print(uv.find_uv_bin())"), @r" + success: true + exit_code: 0 ----- stdout ----- + [VENV]/[BIN]/uv ----- stderr ----- - Traceback (most recent call last): - File "", line 1, in - File "[SITE_PACKAGES]/uv/_find_uv.py", line 28, in find_uv_bin - _matching_parents(_module_path(), "lib/[PYTHON]*/site-packages/uv"), "bin" - File "[SITE_PACKAGES]/uv/_find_uv.py", line 79, in _matching_parents - for part, match_part in zip( - TypeError: zip() takes no keyword arguments - "# + " ); } diff --git a/python/uv/_find_uv.py b/python/uv/_find_uv.py index 736288a4c..12762e50c 100644 --- a/python/uv/_find_uv.py +++ b/python/uv/_find_uv.py @@ -76,8 +76,10 @@ def _matching_parents(path: str | None, match: str) -> str | None: if not all( fnmatch(part, match_part) - for part, match_part in zip( - reversed(parts), reversed(match_parts), strict=False + for part, match_part in ( + zip(reversed(parts), reversed(match_parts), strict=False) + if sys.version_info >= (3, 10) + else zip(reversed(parts), reversed(match_parts)) # noqa: B905 ) ): return None