When is called with a path that does not start with on a bare-relative URL (e.g. ), the method unconditionally prepends , silently turning a path-relative reference into an absolute-path reference. The result resolves differently against any base URL.
Repro
>>> from yarl import URL
>>> url = URL('foo/bar')
>>> str(url.with_path('abs'))
'/abs' # should be 'abs' — the URL is bare-relative, not absolute
>>> url.with_path('abs').is_absolute()
True # was False before .with_path()
Expected
The path's leading slash status should be preserved across for URLs without a netloc: a bare-relative URL stays bare-relative unless the caller explicitly passes a slash-prefixed path.
Workaround
Pass an explicit to keep the slash-prefixed result (this case still works). The fix preserves that behavior.
Risk
Any caller relying on the old behavior of getting back when passing to a bare-relative URL will see a behavior change. That caller can pass explicitly to opt in.
When is called with a path that does not start with on a bare-relative URL (e.g. ), the method unconditionally prepends , silently turning a path-relative reference into an absolute-path reference. The result resolves differently against any base URL.
Repro
Expected
The path's leading slash status should be preserved across for URLs without a netloc: a bare-relative URL stays bare-relative unless the caller explicitly passes a slash-prefixed path.
Workaround
Pass an explicit to keep the slash-prefixed result (this case still works). The fix preserves that behavior.
Risk
Any caller relying on the old behavior of getting back when passing to a bare-relative URL will see a behavior change. That caller can pass explicitly to opt in.