Skip to content

Commit 9f99a40

Browse files
authored
Remove internal _default_port property (#1424)
1 parent 57d69fe commit 9f99a40

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

yarl/_url.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ class _InternalURLCache(TypedDict, total=False):
102102
absolute: bool
103103
scheme: str
104104
raw_authority: str
105-
_default_port: Union[int, None]
106105
authority: str
107106
raw_user: Union[str, None]
108107
user: Union[str, None]
@@ -444,7 +443,9 @@ def __str__(self) -> str:
444443
path = "/"
445444
else:
446445
path = self._path
447-
if (port := self.explicit_port) is not None and port == self._default_port:
446+
if (port := self.explicit_port) is not None and port == DEFAULT_PORTS.get(
447+
self._scheme
448+
):
448449
# port normalization - using None for default ports to remove from rendering
449450
# https://datatracker.ietf.org/doc/html/rfc3986.html#section-6.2.3
450451
host = self.host_subcomponent
@@ -556,7 +557,7 @@ def is_default_port(self) -> bool:
556557
# using the default port unless its a relative URL
557558
# which does not have an implicit port / default port
558559
return self._netloc != ""
559-
return explicit == self._default_port
560+
return explicit == DEFAULT_PORTS.get(self._scheme)
560561

561562
def origin(self) -> "URL":
562563
"""Return an URL with scheme, host and port parts only.
@@ -630,11 +631,6 @@ def raw_authority(self) -> str:
630631
"""
631632
return self._netloc
632633

633-
@cached_property
634-
def _default_port(self) -> Union[int, None]:
635-
"""Default port for the scheme or None if not known."""
636-
return DEFAULT_PORTS.get(self._scheme)
637-
638634
@cached_property
639635
def authority(self) -> str:
640636
"""Decoded authority part of URL.
@@ -771,7 +767,7 @@ def host_port_subcomponent(self) -> Union[str, None]:
771767
# To avoid string manipulation we only call rstrip if
772768
# the last character is a dot.
773769
raw = raw.rstrip(".")
774-
if port is None or port == self._default_port:
770+
if port is None or port == DEFAULT_PORTS.get(self._scheme):
775771
return f"[{raw}]" if ":" in raw else raw
776772
return f"[{raw}]:{port}" if ":" in raw else f"{raw}:{port}"
777773

@@ -783,10 +779,9 @@ def port(self) -> Union[int, None]:
783779
scheme without default port substitution.
784780
785781
"""
786-
port = self.explicit_port
787-
if port is None:
788-
port = self._default_port
789-
return port
782+
if (explicit_port := self.explicit_port) is not None:
783+
return explicit_port
784+
return DEFAULT_PORTS.get(self._scheme)
790785

791786
@cached_property
792787
def explicit_port(self) -> Union[int, None]:

0 commit comments

Comments
 (0)