-
-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Support for Relative Path Calculation #1183
Comments
This idea looks quite interesting. But I think it would be more intuitive if we "subtracted" the shorter link from the longer one. from yarl import URL
target = URL('http://example.com/docs/a.json')
base = URL('http://example.com/docs/')
relative_path = target - base
print(relative_path) # Expected output: 'a.json' So I would just swap the operands. |
I haven't contributed to this repository yet, but it looks like a "good first issue" to me. I'll try to implement your idea today or tomorrow. |
We discovered that approach in #1340 isn't ready to ship so I've opened #1391 to revert it so we can try again. more details starting at #1388 (comment) |
Is your feature request related to a problem?
No response
Describe the solution you'd like
Current Behavior
The
yarl
library provides an intuitive API for handling URL parsing and construction. However, it lacks an operator for directly calculating the relative path between two URLs.Proposed Feature
Introduce support for using the subtraction operator (
-
) to calculate the relative path between twoURL
objects. This would simplify the syntax for relative path calculation, making it more intuitive. The operator could calculate the difference between two URLs' paths and return the relative path.Example Usage
Describe alternatives you've considered
This feature would simplify URL handling in situations where relative paths are frequently needed and would make yarl even more developer-friendly. It would be especially useful in web applications and API development.
Thank you for considering this feature request!
Additional context
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: