@@ -313,13 +313,9 @@ def __new__(
313
313
elif isinstance (val , str ):
314
314
val = str (val )
315
315
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.
323
319
self = object .__new__ (URL )
324
320
self ._scheme = ""
325
321
self ._netloc = ""
@@ -970,8 +966,7 @@ def suffixes(self) -> tuple[str, ...]:
970
966
971
967
def _make_child (self , paths : "Sequence[str]" , encoded : bool = False ) -> "URL" :
972
968
"""
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,
975
970
keep existing, but do not create new, empty segments
976
971
"""
977
972
parsed : list [str ] = []
@@ -1297,8 +1292,7 @@ def with_name(self, name: str) -> "URL":
1297
1292
if name in ("." , ".." ):
1298
1293
raise ValueError (". and .. values are forbidden" )
1299
1294
parts = list (self .raw_parts )
1300
- scheme , netloc = self ._scheme , self ._netloc
1301
- if netloc :
1295
+ if netloc := self ._netloc :
1302
1296
if len (parts ) == 1 :
1303
1297
parts .append (name )
1304
1298
else :
@@ -1308,7 +1302,7 @@ def with_name(self, name: str) -> "URL":
1308
1302
parts [- 1 ] = name
1309
1303
if parts [0 ] == "/" :
1310
1304
parts [0 ] = "" # replace leading '/'
1311
- return self ._from_parts (scheme , netloc , "/" .join (parts ), "" , "" )
1305
+ return self ._from_parts (self . _scheme , netloc , "/" .join (parts ), "" , "" )
1312
1306
1313
1307
def with_suffix (self , suffix : str ) -> "URL" :
1314
1308
"""Return a new URL with suffix (file extension of name) replaced.
0 commit comments