Skip to content

More consistent handling of implicit default ports #1542

Open
@purplezimmermann

Description

@purplezimmermann

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__()

>>> URL('http://github.com') == URL('http://github.com:80')
False

Although:

>>> 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. #921 (comment) closed the issue – mentioning #1033 as probable fix. Yet the latter only addressed .__str__() conversion – BTW also discarding default ports:

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

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

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

>>> URL('http://github.com').raw_authority
'github.com:80'

Describe alternatives you've considered

None so far ... :)

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions