@@ -4,7 +4,7 @@ use std::str::Chars;
4
4
5
5
use pyo3:: intern;
6
6
use pyo3:: prelude:: * ;
7
- use pyo3:: types:: { PyDict , PyList , PyType } ;
7
+ use pyo3:: types:: { PyDict , PyList } ;
8
8
9
9
use ahash:: AHashSet ;
10
10
use url:: { ParseError , SyntaxViolation , Url } ;
@@ -26,7 +26,6 @@ type AllowedSchemas = Option<(AHashSet<String>, String)>;
26
26
#[ derive( Debug , Clone ) ]
27
27
pub struct UrlValidator {
28
28
strict : bool ,
29
- cls : Option < Py < PyType > > ,
30
29
max_length : Option < usize > ,
31
30
allowed_schemes : AllowedSchemas ,
32
31
host_required : bool ,
@@ -48,7 +47,6 @@ impl BuildValidator for UrlValidator {
48
47
49
48
Ok ( Self {
50
49
strict : is_strict ( schema, config) ?,
51
- cls : schema. get_as ( intern ! ( schema. py( ) , "cls" ) ) ?,
52
50
max_length : schema. get_as ( intern ! ( schema. py( ) , "max_length" ) ) ?,
53
51
host_required : schema. get_as ( intern ! ( schema. py( ) , "host_required" ) ) ?. unwrap_or ( false ) ,
54
52
default_host : schema. get_as ( intern ! ( schema. py( ) , "default_host" ) ) ?,
@@ -61,7 +59,7 @@ impl BuildValidator for UrlValidator {
61
59
}
62
60
}
63
61
64
- impl_py_gc_traverse ! ( UrlValidator { cls } ) ;
62
+ impl_py_gc_traverse ! ( UrlValidator { } ) ;
65
63
66
64
impl Validator for UrlValidator {
67
65
fn validate < ' py > (
@@ -95,31 +93,7 @@ impl Validator for UrlValidator {
95
93
Ok ( ( ) ) => {
96
94
// Lax rather than strict to preserve V2.4 semantic that str wins over url in union
97
95
state. floor_exactness ( Exactness :: Lax ) ;
98
-
99
- if let Some ( url_subclass) = & self . cls {
100
- // TODO: we do an extra build for a subclass here, we should avoid this
101
- // in v2.11 for perf reasons, but this is a worthwhile patch for now
102
- // given that we want isinstance to work properly for subclasses of Url
103
- let py_url = match either_url {
104
- EitherUrl :: Py ( py_url) => py_url. get ( ) . clone ( ) ,
105
- EitherUrl :: Rust ( rust_url) => PyUrl :: new ( rust_url) ,
106
- } ;
107
-
108
- let py_url = PyUrl :: build (
109
- url_subclass. bind ( py) ,
110
- py_url. scheme ( ) ,
111
- py_url. host ( ) ,
112
- py_url. username ( ) ,
113
- py_url. password ( ) ,
114
- py_url. port ( ) ,
115
- py_url. path ( ) . filter ( |path| * path != "/" ) ,
116
- py_url. query ( ) ,
117
- py_url. fragment ( ) ,
118
- ) ?;
119
- Ok ( py_url. into_py ( py) )
120
- } else {
121
- Ok ( either_url. into_py ( py) )
122
- }
96
+ Ok ( either_url. into_py ( py) )
123
97
}
124
98
Err ( error_type) => Err ( ValError :: new ( error_type, input) ) ,
125
99
}
@@ -212,7 +186,6 @@ impl CopyFromPyUrl for EitherUrl<'_> {
212
186
#[ derive( Debug , Clone ) ]
213
187
pub struct MultiHostUrlValidator {
214
188
strict : bool ,
215
- cls : Option < Py < PyType > > ,
216
189
max_length : Option < usize > ,
217
190
allowed_schemes : AllowedSchemas ,
218
191
host_required : bool ,
@@ -240,7 +213,6 @@ impl BuildValidator for MultiHostUrlValidator {
240
213
}
241
214
Ok ( Self {
242
215
strict : is_strict ( schema, config) ?,
243
- cls : schema. get_as ( intern ! ( schema. py( ) , "cls" ) ) ?,
244
216
max_length : schema. get_as ( intern ! ( schema. py( ) , "max_length" ) ) ?,
245
217
allowed_schemes,
246
218
host_required : schema. get_as ( intern ! ( schema. py( ) , "host_required" ) ) ?. unwrap_or ( false ) ,
@@ -253,7 +225,7 @@ impl BuildValidator for MultiHostUrlValidator {
253
225
}
254
226
}
255
227
256
- impl_py_gc_traverse ! ( MultiHostUrlValidator { cls } ) ;
228
+ impl_py_gc_traverse ! ( MultiHostUrlValidator { } ) ;
257
229
258
230
impl Validator for MultiHostUrlValidator {
259
231
fn validate < ' py > (
@@ -286,38 +258,7 @@ impl Validator for MultiHostUrlValidator {
286
258
Ok ( ( ) ) => {
287
259
// Lax rather than strict to preserve V2.4 semantic that str wins over url in union
288
260
state. floor_exactness ( Exactness :: Lax ) ;
289
-
290
- if let Some ( url_subclass) = & self . cls {
291
- // TODO: we do an extra build for a subclass here, we should avoid this
292
- // in v2.11 for perf reasons, but this is a worthwhile patch for now
293
- // given that we want isinstance to work properly for subclasses of Url
294
- let py_url = match multi_url {
295
- EitherMultiHostUrl :: Py ( py_url) => py_url. get ( ) . clone ( ) ,
296
- EitherMultiHostUrl :: Rust ( rust_url) => rust_url,
297
- } ;
298
-
299
- let hosts = py_url
300
- . hosts ( py) ?
301
- . into_iter ( )
302
- . map ( |host| host. extract ( ) . expect ( "host should be a valid UrlHostParts" ) )
303
- . collect ( ) ;
304
-
305
- let py_url = PyMultiHostUrl :: build (
306
- url_subclass. bind ( py) ,
307
- py_url. scheme ( ) ,
308
- Some ( hosts) ,
309
- py_url. path ( ) . filter ( |path| * path != "/" ) ,
310
- py_url. query ( ) ,
311
- py_url. fragment ( ) ,
312
- None ,
313
- None ,
314
- None ,
315
- None ,
316
- ) ?;
317
- Ok ( py_url. into_py ( py) )
318
- } else {
319
- Ok ( multi_url. into_py ( py) )
320
- }
261
+ Ok ( multi_url. into_py ( py) )
321
262
}
322
263
Err ( error_type) => Err ( ValError :: new ( error_type, input) ) ,
323
264
}
0 commit comments