Skip to content

Commit

Permalink
Small internal code cleanups (#1335)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Oct 19, 2024
1 parent 7d76bed commit 29bc0cc
Showing 1 changed file with 9 additions and 25 deletions.
34 changes: 9 additions & 25 deletions yarl/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,7 @@ def user(self) -> Union[str, None]:
None if user is missing.
"""
raw_user = self.raw_user
if raw_user is None:
if (raw_user := self.raw_user) is None:
return None
return self._UNQUOTER(raw_user)

Expand All @@ -703,8 +702,7 @@ def password(self) -> Union[str, None]:
None if password is missing.
"""
raw_password = self.raw_password
if raw_password is None:
if (raw_password := self.raw_password) is None:
return None
return self._UNQUOTER(raw_password)

Expand Down Expand Up @@ -785,10 +783,7 @@ def raw_path(self) -> str:
/ for absolute URLs without path part.
"""
ret = self._val.path
if not ret and self._val.netloc:
ret = "/"
return ret
return "/" if not (path := self._val.path) and self._val.netloc else path

@cached_property
def path(self) -> str:
Expand Down Expand Up @@ -846,16 +841,12 @@ def query_string(self) -> str:
@cached_property
def path_qs(self) -> str:
"""Decoded path of URL with query."""
if not self.query_string:
return self.path
return f"{self.path}?{self.query_string}"
return self.path if not (q := self.query_string) else f"{self.path}?{q}"

@cached_property
def raw_path_qs(self) -> str:
"""Encoded path of URL with query."""
if not self._val.query:
return self.raw_path
return f"{self.raw_path}?{self._val.query}"
return self.raw_path if not (q := self._val.query) else f"{self.raw_path}?{q}"

@cached_property
def raw_fragment(self) -> str:
Expand Down Expand Up @@ -918,14 +909,10 @@ def parent(self) -> "URL":
def raw_name(self) -> str:
"""The last part of raw_parts."""
parts = self.raw_parts
if self._val.netloc:
parts = parts[1:]
if not parts:
return ""
else:
return parts[-1]
else:
if not self._val.netloc:
return parts[-1]
parts = parts[1:]
return parts[-1] if parts else ""

@cached_property
def name(self) -> str:
Expand All @@ -936,10 +923,7 @@ def name(self) -> str:
def raw_suffix(self) -> str:
name = self.raw_name
i = name.rfind(".")
if 0 < i < len(name) - 1:
return name[i:]
else:
return ""
return name[i:] if 0 < i < len(name) - 1 else ""

@cached_property
def suffix(self) -> str:
Expand Down

0 comments on commit 29bc0cc

Please sign in to comment.