More consistent handling of implicit default ports
- Vorherrschende Sprache
- Python
- Sterne
- 1.5k
- Forks
- 215
- Ø Merge
- 1 T. 2 Min.
- Gemergte PRs (30 T.)
- 13
Beschreibung
### Is your feature request related to a problem?
Yes. Except `.explicit_port`, most public API members produce similar results for URLs w/ explicit & implicit default ports – ignoring or discarding default ports whenever irrelevant. The remaining exceptions lead IMO to inconsistent, unexpected behavior:
#### 1. `.__eq__()`
```python
>>> URL('http://github.com') == URL('http://github.com:80')
False
```
Although:
```python
>>> str(URL('http://github.com')) == str(URL('http://github.com:80'))
True
>>> URL('http://github.com').port == URL('http://github.com:80').port
True
```
This comparison behavior was already discussed in #921. https://github.com/aio-libs/yarl/issues/921#issuecomment-2324837518 closed the issue – mentioning https://github.com/aio-libs/yarl/pull/1033 as probable fix. Yet the latter only addressed `.__str__()` conversion – BTW also discarding default ports:
```python
>>> str(URL('http://github.com:80'))
'http://github.com'
```
#### 2. `.authority` & `.raw_authority`
Should only differ in encoding, right? (& should IMO follow the discarding logic as well) – yet:
```python
>>> URL('http://github.com').authority
'github.com:80'
>>> URL('http://github.com:80').authority
'github.com:80'
>>> URL('http://github.com').raw_authority
'github.com'
>>> URL('http://github.com:80').raw_authority
'github.com:80'
```
### Describe the solution you'd like
#### 1. Ignore default ports in comparisons & `.__hash__()`
#### 2. Either:
```python
>>> URL('http://github.com').authority
'github.com'
>>> URL('http://github.com:80').authority
'github.com'
>>> URL('http://github.com:80').raw_authority
'github.com'
```
Or:
```python
>>> URL('http://github.com').raw_authority
'github.com:80'
```
### Describe alternatives you've considered
None so far ... :)
### Additional context
_No response_
### Code of Conduct
- [x] I agree to follow the aio-libs Code of Conduct
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.