@@ -216,7 +216,6 @@ def pre_encoded_url(url_str: str) -> "URL":
216
216
217
217
@rewrite_module
218
218
class URL :
219
-
220
219
# Don't derive from str
221
220
# follow pathlib.Path design
222
221
# probably URL will not suffer from pathlib problems:
@@ -1338,31 +1337,18 @@ def join(self, url: "URL") -> "URL":
1338
1337
if type (url ) is not URL :
1339
1338
raise TypeError ("url should be URL" )
1340
1339
1341
- orig_scheme = self ._scheme
1342
- orig_path = self ._path
1343
- orig_query = self ._query
1344
- orig_fragment = self ._fragment
1345
- join_netloc = url ._netloc
1346
- join_path = url ._path
1347
- join_query = url ._query
1348
- join_fragment = url ._fragment
1349
- scheme = url ._scheme or orig_scheme
1350
-
1351
- if scheme != orig_scheme or scheme not in USES_RELATIVE :
1340
+ scheme = url ._scheme or self ._scheme
1341
+ if scheme != self ._scheme or scheme not in USES_RELATIVE :
1352
1342
return url
1353
1343
1354
1344
# scheme is in uses_authority as uses_authority is a superset of uses_relative
1355
- if join_netloc and scheme in USES_AUTHORITY :
1345
+ if ( join_netloc := url . _netloc ) and scheme in USES_AUTHORITY :
1356
1346
return self ._from_parts (
1357
- scheme , join_netloc , join_path , join_query , join_fragment
1347
+ scheme , join_netloc , url . _path , url . _query , url . _fragment
1358
1348
)
1359
1349
1360
- fragment = join_fragment if join_path or join_fragment else orig_fragment
1361
- query = join_query if join_path or join_query else orig_query
1362
-
1363
- if not join_path :
1364
- path = orig_path
1365
- else :
1350
+ orig_path = self ._path
1351
+ if join_path := url ._path :
1366
1352
if join_path [0 ] == "/" :
1367
1353
path = join_path
1368
1354
elif not orig_path :
@@ -1379,15 +1365,19 @@ def join(self, url: "URL") -> "URL":
1379
1365
if orig_path [0 ] == "/" :
1380
1366
path = path [1 :]
1381
1367
path = normalize_path (path ) if "." in path else path
1368
+ else :
1369
+ path = orig_path
1382
1370
1383
- url = object .__new__ (URL )
1384
- url ._scheme = scheme
1385
- url ._netloc = self ._netloc
1386
- url ._path = path
1387
- url ._query = query
1388
- url ._fragment = fragment
1389
- url ._cache = {}
1390
- return url
1371
+ new_url = object .__new__ (URL )
1372
+ new_url ._scheme = scheme
1373
+ new_url ._netloc = self ._netloc
1374
+ new_url ._path = path
1375
+ new_url ._query = url ._query if join_path or url ._query else self ._query
1376
+ new_url ._fragment = (
1377
+ url ._fragment if join_path or url ._fragment else self ._fragment
1378
+ )
1379
+ new_url ._cache = {}
1380
+ return new_url
1391
1381
1392
1382
def joinpath (self , * other : str , encoded : bool = False ) -> "URL" :
1393
1383
"""Return a new URL with the elements in other appended to the path."""
0 commit comments