aio-libs / aio-libs/yarl

Add Support for Relative Path Calculation

未關閉
#1,183 4 則留言 0 個 reaction 已指派 1 人 已被 @babieiev 認領 在 GitHub 檢視
enhancement
主要語言
Python
星號
1.5k
分支
215
平均合併
1 天 2 分鐘
30 天內合併 PR
13

描述

### 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 two `URL` 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
```python
from yarl import URL

url1 = URL('http://example.com/docs/')
url2 = URL('http://example.com/docs/a.json')

relative_path = url1 - url2 # Proposed feature

print(relative_path) # Expected output: 'a.json'
```

### 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

- [X] I agree to follow the aio-libs Code of Conduct

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。