Make uv_fs::PythonExt::escape_for_python completely robust#20470
Open
EliteTK wants to merge 4 commits into
Open
Make uv_fs::PythonExt::escape_for_python completely robust#20470EliteTK wants to merge 4 commits into
uv_fs::PythonExt::escape_for_python completely robust#20470EliteTK wants to merge 4 commits into
Conversation
The filter is very broad to the point that it cannot be used to verify expectations. But making it narrow enough for that would require parametrization or a second filter, and only one test exercises this path at the moment, so I've decided to inline it.
Ty is the only consumer, it doesn't unescape the result. This probably worked fine for Windows because it eats duplicate backslashes, it would only break there if someone put a double-quote in their path (which nobdy does). On *nix it would break in both cases but again nobody does that. Regardless, it shouldn't be escaped, and eating the utf-8 error silently would just produce a weird broken result. So I opted to make it loud... Could make it a warning? [^ty]: <https://github.com/astral-sh/ruff/blob/db195f3a494c55feeef225daa5de0b803a5253ac/crates/ty_site_packages/src/lib.rs#L1081-L1117>
EliteTK
force-pushed
the
tk/robust-fs-python-escape
branch
from
July 16, 2026 14:11
113cd66 to
4dee44f
Compare
EliteTK
force-pushed
the
tk/robust-fs-python-escape
branch
from
July 16, 2026 14:21
4dee44f to
242a5f4
Compare
EliteTK
force-pushed
the
tk/robust-fs-python-escape
branch
from
July 16, 2026 15:01
242a5f4 to
72542b1
Compare
EliteTK
marked this pull request as ready for review
July 16, 2026 15:01
EliteTK
force-pushed
the
tk/robust-fs-python-escape
branch
from
July 16, 2026 15:33
72542b1 to
6988bdd
Compare
EliteTK
force-pushed
the
tk/fix-extends-environment-path
branch
from
July 16, 2026 16:02
7367964 to
e4a8528
Compare
Previously we only handled a subset of paths and silently broke them if they contained invalid unicode. This now handles all possible paths in a way that python would accept losslessly. In a lot of cases we assume paths are valid unicode elsewhere, but making this work properly is a one-off exercise, and now we no longer need to worry about it. This also cleans up uv-build-frontend using its own custom implementation, it now pulls from uv_fs.
EliteTK
force-pushed
the
tk/robust-fs-python-escape
branch
from
July 16, 2026 16:09
6988bdd to
57c584a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Previously we only handled a subset of paths and silently broke them if they contained invalid unicode.
This now handles all possible paths in a way that python would accept losslessly.
In a lot of cases we assume paths are valid unicode elsewhere, but making this work properly is a one-off exercise, and now we no longer need to worry about it.
This also cleans up uv-build-frontend using its own custom implementation, it now pulls from uv_fs.
Test Plan
Some testing was manual to ensure we correctly handle the result in Python.
There's an exhaustive test for *nix, and a selective test for Windows.