@@ -246,8 +246,9 @@ def build_pre_encoded_url(
246
246
return self
247
247
248
248
249
- @lru_cache
250
- def from_parts (scheme : str , netloc : str , path : str , query : str , fragment : str ) -> "URL" :
249
+ def from_parts_uncached (
250
+ scheme : str , netloc : str , path : str , query : str , fragment : str
251
+ ) -> "URL" :
251
252
"""Create a new URL from parts."""
252
253
self = object .__new__ (URL )
253
254
self ._scheme = scheme
@@ -259,6 +260,9 @@ def from_parts(scheme: str, netloc: str, path: str, query: str, fragment: str) -
259
260
return self
260
261
261
262
263
+ from_parts = lru_cache (from_parts_uncached )
264
+
265
+
262
266
@rewrite_module
263
267
class URL :
264
268
# Don't derive from str
@@ -1170,7 +1174,9 @@ def with_query(self, *args: Any, **kwargs: Any) -> "URL":
1170
1174
"""
1171
1175
# N.B. doesn't cleanup query/fragment
1172
1176
query = get_str_query (* args , ** kwargs ) or ""
1173
- return from_parts (self ._scheme , self ._netloc , self ._path , query , self ._fragment )
1177
+ return from_parts_uncached (
1178
+ self ._scheme , self ._netloc , self ._path , query , self ._fragment
1179
+ )
1174
1180
1175
1181
@overload
1176
1182
def extend_query (self , query : Query ) -> "URL" : ...
@@ -1196,7 +1202,9 @@ def extend_query(self, *args: Any, **kwargs: Any) -> "URL":
1196
1202
query += new_query if query [- 1 ] == "&" else f"&{ new_query } "
1197
1203
else :
1198
1204
query = new_query
1199
- return from_parts (self ._scheme , self ._netloc , self ._path , query , self ._fragment )
1205
+ return from_parts_uncached (
1206
+ self ._scheme , self ._netloc , self ._path , query , self ._fragment
1207
+ )
1200
1208
1201
1209
@overload
1202
1210
def update_query (self , query : Query ) -> "URL" : ...
@@ -1253,7 +1261,9 @@ def update_query(self, *args: Any, **kwargs: Any) -> "URL":
1253
1261
"Invalid query type: only str, mapping or "
1254
1262
"sequence of (key, value) pairs is allowed"
1255
1263
)
1256
- return from_parts (self ._scheme , self ._netloc , self ._path , query , self ._fragment )
1264
+ return from_parts_uncached (
1265
+ self ._scheme , self ._netloc , self ._path , query , self ._fragment
1266
+ )
1257
1267
1258
1268
def without_query_params (self , * query_params : str ) -> "URL" :
1259
1269
"""Remove some keys from query part and return new URL."""
0 commit comments