yarl icon indicating copy to clipboard operation
yarl copied to clipboard

Support using the subtraction operator to get the relative path between URLs

Open oleksbabieiev opened this issue 4 months ago • 0 comments

What do these changes do?

Support for using the subtraction operator to calculate the difference between the paths of two URLs. A new URL with the relative path is returned to the user.

Usage:

from yarl import URL

target = URL("http://example.com/path/index.html")
base = URL("http://example.com/path/")

rel = target - base

print(rel)  # output: "index.html"

Are there changes in behavior for the user?

Now the user can easily calculate the relative path between two URLs!

Related issue number

Resolves #1183

Checklist

  • [x] I think the code is well written
  • [x] Unit tests for the changes exist
  • [x] Documentation reflects the changes

oleksbabieiev avatar Oct 20 '24 15:10 oleksbabieiev