aio-libs / aio-libs/yarl

Add Support for Relative Path Calculation

Aperta
#1,183 4 commenti 0 reazioni 1 assegnatario Rivendicata da @babieiev Vedi su GitHub
enhancement
Lingua principale
Python
Stelle
1.5k
Fork
215
Merge medio
1g 2m
PR unite (30g)
13

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.