Skip to content

Commit 8ce8d67

Browse files
authored
Small cleanups as a followup to removing self._val (#1399)
1 parent 07798bf commit 8ce8d67

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

yarl/_url.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,9 @@ def __new__(
313313
elif isinstance(val, str):
314314
val = str(val)
315315
elif val is UNDEFINED:
316-
# Special case for UNDEFINED
317-
# since it might be unpickling
318-
# and we do not want to cache
319-
# as the `__set_state__` call would
320-
# mutate the URL object in the
321-
# `pre_encoded_url` or `encoded_url`
322-
# caches
316+
# Special case for UNDEFINED since it might be unpickling and we do
317+
# not want to cache as the `__set_state__` call would mutate the URL
318+
# object in the `pre_encoded_url` or `encoded_url` caches.
323319
self = object.__new__(URL)
324320
self._scheme = ""
325321
self._netloc = ""
@@ -970,8 +966,7 @@ def suffixes(self) -> tuple[str, ...]:
970966

971967
def _make_child(self, paths: "Sequence[str]", encoded: bool = False) -> "URL":
972968
"""
973-
add paths to self._path, accounting
974-
for absolute vs relative paths,
969+
add paths to self._path, accounting for absolute vs relative paths,
975970
keep existing, but do not create new, empty segments
976971
"""
977972
parsed: list[str] = []
@@ -1297,8 +1292,7 @@ def with_name(self, name: str) -> "URL":
12971292
if name in (".", ".."):
12981293
raise ValueError(". and .. values are forbidden")
12991294
parts = list(self.raw_parts)
1300-
scheme, netloc = self._scheme, self._netloc
1301-
if netloc:
1295+
if netloc := self._netloc:
13021296
if len(parts) == 1:
13031297
parts.append(name)
13041298
else:
@@ -1308,7 +1302,7 @@ def with_name(self, name: str) -> "URL":
13081302
parts[-1] = name
13091303
if parts[0] == "/":
13101304
parts[0] = "" # replace leading '/'
1311-
return self._from_parts(scheme, netloc, "/".join(parts), "", "")
1305+
return self._from_parts(self._scheme, netloc, "/".join(parts), "", "")
13121306

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

0 commit comments

Comments
 (0)