Skip to content

More consistent handling of implicit default ports #1542

@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