diff --git a/yarl/_url.py b/yarl/_url.py index d20a6106..8eee061d 100644 --- a/yarl/_url.py +++ b/yarl/_url.py @@ -527,9 +527,7 @@ def __setstate__(self, state): def _cache_netloc(self) -> None: """Cache the netloc parts of the URL.""" - c = self._cache - split_loc = split_netloc(self._netloc) - c["raw_user"], c["raw_password"], c["raw_host"], c["explicit_port"] = split_loc + self._cache.update(_split_netloc_to_cache(self._netloc)) def is_absolute(self) -> bool: """A check for absolute URLs. @@ -1403,6 +1401,18 @@ def human_repr(self) -> str: _DEFAULT_ENCODE_SIZE = 512 +@lru_cache +def _split_netloc_to_cache(netloc: str) -> dict[str, Any]: + """Split netloc into cache.""" + user, password, host, port = split_netloc(netloc) + return { + "raw_user": user, + "raw_password": password, + "raw_host": host, + "explicit_port": port, + } + + @lru_cache(_DEFAULT_IDNA_SIZE) def _idna_decode(raw: str) -> str: try: