Skip to content

Commit

Permalink
Small cleanups as a followup to removing self._val (#1399)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Oct 30, 2024
1 parent 07798bf commit 8ce8d67
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions yarl/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,9 @@ def __new__(
elif isinstance(val, str):
val = str(val)
elif val is UNDEFINED:
# Special case for UNDEFINED
# since it might be unpickling
# and we do not want to cache
# as the `__set_state__` call would
# mutate the URL object in the
# `pre_encoded_url` or `encoded_url`
# caches
# Special case for UNDEFINED since it might be unpickling and we do
# not want to cache as the `__set_state__` call would mutate the URL
# object in the `pre_encoded_url` or `encoded_url` caches.
self = object.__new__(URL)
self._scheme = ""
self._netloc = ""
Expand Down Expand Up @@ -970,8 +966,7 @@ def suffixes(self) -> tuple[str, ...]:

def _make_child(self, paths: "Sequence[str]", encoded: bool = False) -> "URL":
"""
add paths to self._path, accounting
for absolute vs relative paths,
add paths to self._path, accounting for absolute vs relative paths,
keep existing, but do not create new, empty segments
"""
parsed: list[str] = []
Expand Down Expand Up @@ -1297,8 +1292,7 @@ def with_name(self, name: str) -> "URL":
if name in (".", ".."):
raise ValueError(". and .. values are forbidden")
parts = list(self.raw_parts)
scheme, netloc = self._scheme, self._netloc
if netloc:
if netloc := self._netloc:
if len(parts) == 1:
parts.append(name)
else:
Expand All @@ -1308,7 +1302,7 @@ def with_name(self, name: str) -> "URL":
parts[-1] = name
if parts[0] == "/":
parts[0] = "" # replace leading '/'
return self._from_parts(scheme, netloc, "/".join(parts), "", "")
return self._from_parts(self._scheme, netloc, "/".join(parts), "", "")

def with_suffix(self, suffix: str) -> "URL":
"""Return a new URL with suffix (file extension of name) replaced.
Expand Down

0 comments on commit 8ce8d67

Please sign in to comment.