Encode URL serialization policies in the type system #2711
Shouldn't this use SafeUrl<PreserveUrl> at ProxyUrl(DisplaySafeUrl); instead? We should be replacing DisplaySafeUrl entirely
<!-- __CODSPEED_PERFORMANCE_REPORT_COMMENT__ -->
Merging this PR will degrade performance by 13.01%
<details>
<summary>:warning: <b>8 benchmarks spent significant time in system calls</b></summary>
System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.
> Measurement and system calls
> - `discover_workspace_from_all_members_with_excludes
-discover_workspace_from_all_members
-resolve_warm_jupyter
-run_python_version_synthetic_workspace
-install_wheel_many_files
-resolve_warm_airflow
-unpack_sdist_many_files
-resolve_warm_jupyter_universal
</details>
<details>
<summary>:warning: <b>Different runtime environments detected</b></summary>
Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.
> Open the report in CodSpeed to investigate
</details>
❌ 1 regressed benchmark ✅ 68 untouched benchmarks ⏩ 35 skipped benchmarks[^skipped]
[!WARNING]
Please fix the performance issues or acknowledge them on CodSpeed.
Performance Changes
| | Mode | Benchmark | BASE | HEAD | Efficiency |
| --- | ---- | --------- | ------ | ------ | ---------- |
| ❌ :warning: | Simulation | discover_workspace_from_all_members_with_excludes | 142.7 ms | 164.1 ms | -13.01% |
[!TIP]
Investigate this regression by commenting @codspeedbot fix this regression` on this PR, or directly use the CodSpeed MCP with your agent.
---
<sub>Comparing <code>zaniebot/safe-url-policies-20261014</code> (3dff9d7) with <code>zaniebot/safe-url-rename-20261014</code> (f85db54)</sub>
<a href="https://app.codspeed.io/astral-sh/uv-dev/branches/zaniebot%2Fsafe-url-policies-20261014?utm_source=github&utm_medium=comment-v2&utm_content=button">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://codspeed.io/pr-report/open-in-codspeed-dark.svg">
<source media="(prefers-color-scheme: light)" srcset="https://codspeed.io/pr-report/open-in-codspeed-light.svg">
<img alt="Open in CodSpeed" src="https://codspeed.io/pr-report/open-in-codspeed-light.svg" width="169" height="32">
</picture>
</a>
[^skipped]: 35 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.
[P3] Guard serialization methods against implicit Deref fallback
With serde::Serialize in scope, SafeUrl<Unserializable>.serialize(serializer) still compiles: method lookup dereferences to Url::serialize and writes the complete URL. Likewise, serialize_internal falls through to Url for both Unserializable and Stripped. Consequently, accidentally removing the policy from a hand-written serializer such as ProxyUrl::serialize would silently retain raw persistence, although the derive-based compile-fail tests pass. Consider shadowing these methods with policy-bound inherent methods and adding compile-fail coverage for method-call syntax. This would require an explicit raw-URL conversion to bypass the policy.
love to see it
Hm, not sure why this exist, need to look into it
Promoted to #22600.
zanieb
zaniebot
SafeUrlcurrently serializes the full URL, so fields can persist credentials without an explicit choice. Add a type-level policy that defaults toUnserializable;Strippedremoves sensitive userinfo while retaining the complete query, andRawserializes the full parsed URL.DisplayandDebugremain redacted. Index URLs inpylock.tomland publish URLs in tool receipts useStripped.This is an alternative to astral-sh/uv#22356, astral-sh/uv#22357, and astral-sh/uv#22358, combined in #2712.
StrippedandRawfollow the same serialization rules asPersistSafeUrlandCredentialPersistingUrl. UsingSafeUrl<P>carries the policy throughVerbatimUrl, stored fields, and transformations such asjoin; shared implementations are generic over the policy. The inherentserializeandserialize_internalmethods prevent fallback throughDeref; the latter requiresRaw. The comparison stack also changes howDirectUrlmetadata is parsed and written; this PR retains its string fields and existing behavior.Stacked on #2721.