@@ -4,7 +4,7 @@ use std::str::Chars;
44
55use pyo3:: intern;
66use pyo3:: prelude:: * ;
7- use pyo3:: types:: { PyDict , PyList , PyType } ;
7+ use pyo3:: types:: { PyDict , PyList } ;
88
99use ahash:: AHashSet ;
1010use url:: { ParseError , SyntaxViolation , Url } ;
@@ -26,7 +26,6 @@ type AllowedSchemas = Option<(AHashSet<String>, String)>;
2626#[ derive( Debug , Clone ) ]
2727pub struct UrlValidator {
2828 strict : bool ,
29- cls : Option < Py < PyType > > ,
3029 max_length : Option < usize > ,
3130 allowed_schemes : AllowedSchemas ,
3231 host_required : bool ,
@@ -48,7 +47,6 @@ impl BuildValidator for UrlValidator {
4847
4948 Ok ( Self {
5049 strict : is_strict ( schema, config) ?,
51- cls : schema. get_as ( intern ! ( schema. py( ) , "cls" ) ) ?,
5250 max_length : schema. get_as ( intern ! ( schema. py( ) , "max_length" ) ) ?,
5351 host_required : schema. get_as ( intern ! ( schema. py( ) , "host_required" ) ) ?. unwrap_or ( false ) ,
5452 default_host : schema. get_as ( intern ! ( schema. py( ) , "default_host" ) ) ?,
@@ -61,7 +59,7 @@ impl BuildValidator for UrlValidator {
6159 }
6260}
6361
64- impl_py_gc_traverse ! ( UrlValidator { cls } ) ;
62+ impl_py_gc_traverse ! ( UrlValidator { } ) ;
6563
6664impl Validator for UrlValidator {
6765 fn validate < ' py > (
@@ -95,31 +93,7 @@ impl Validator for UrlValidator {
9593 Ok ( ( ) ) => {
9694 // Lax rather than strict to preserve V2.4 semantic that str wins over url in union
9795 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) )
12397 }
12498 Err ( error_type) => Err ( ValError :: new ( error_type, input) ) ,
12599 }
@@ -212,7 +186,6 @@ impl CopyFromPyUrl for EitherUrl<'_> {
212186#[ derive( Debug , Clone ) ]
213187pub struct MultiHostUrlValidator {
214188 strict : bool ,
215- cls : Option < Py < PyType > > ,
216189 max_length : Option < usize > ,
217190 allowed_schemes : AllowedSchemas ,
218191 host_required : bool ,
@@ -240,7 +213,6 @@ impl BuildValidator for MultiHostUrlValidator {
240213 }
241214 Ok ( Self {
242215 strict : is_strict ( schema, config) ?,
243- cls : schema. get_as ( intern ! ( schema. py( ) , "cls" ) ) ?,
244216 max_length : schema. get_as ( intern ! ( schema. py( ) , "max_length" ) ) ?,
245217 allowed_schemes,
246218 host_required : schema. get_as ( intern ! ( schema. py( ) , "host_required" ) ) ?. unwrap_or ( false ) ,
@@ -253,7 +225,7 @@ impl BuildValidator for MultiHostUrlValidator {
253225 }
254226}
255227
256- impl_py_gc_traverse ! ( MultiHostUrlValidator { cls } ) ;
228+ impl_py_gc_traverse ! ( MultiHostUrlValidator { } ) ;
257229
258230impl Validator for MultiHostUrlValidator {
259231 fn validate < ' py > (
@@ -286,38 +258,7 @@ impl Validator for MultiHostUrlValidator {
286258 Ok ( ( ) ) => {
287259 // Lax rather than strict to preserve V2.4 semantic that str wins over url in union
288260 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) )
321262 }
322263 Err ( error_type) => Err ( ValError :: new ( error_type, input) ) ,
323264 }
0 commit comments