Skip to content

Commit

Permalink
Add missing type for _val to _InternalURLCache TypedDict (#1403)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Oct 30, 2024
1 parent 979e06a commit fb25462
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions yarl/_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
UNSAFE_URL_BYTES_TO_REMOVE = ["\t", "\r", "\n"]
USES_AUTHORITY = frozenset(uses_netloc)

SplitURL = tuple[str, str, str, str, str]
SplitURLType = tuple[str, str, str, str, str]


def split_url(url: str) -> SplitURL:
def split_url(url: str) -> SplitURLType:
"""Split URL into parts."""
# Adapted from urllib.parse.urlsplit
# Only lstrip url as some applications rely on preserving trailing space.
Expand Down
11 changes: 6 additions & 5 deletions yarl/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from ._parse import (
USES_AUTHORITY,
SplitURL,
SplitURLType,
make_netloc,
split_netloc,
split_url,
Expand Down Expand Up @@ -97,6 +97,7 @@ class CacheInfo(TypedDict):


class _InternalURLCache(TypedDict, total=False):
_val: SplitURLType
_origin: "URL"
absolute: bool
scheme: str
Expand Down Expand Up @@ -419,10 +420,6 @@ def build(
url._cache = {}
return url

@cached_property
def _val(self) -> SplitURL:
return (self._scheme, self._netloc, self._path, self._query, self._fragment)

@classmethod
def _from_parts(
cls, scheme: str, netloc: str, path: str, query: str, fragment: str
Expand Down Expand Up @@ -568,6 +565,10 @@ def origin(self) -> "URL":
# TODO: add a keyword-only option for keeping user/pass maybe?
return self._origin

@cached_property
def _val(self) -> SplitURLType:
return (self._scheme, self._netloc, self._path, self._query, self._fragment)

@cached_property
def _origin(self) -> "URL":
"""Return an URL with scheme, host and port parts only.
Expand Down

0 comments on commit fb25462

Please sign in to comment.