@@ -128,19 +128,18 @@ impl UrlPattern {
128128 ) )
129129 }
130130
131- fn __repr__ ( & self , py : Python ) -> String {
131+ fn __repr__ ( & self , py : Python ) -> PyResult < String > {
132132 let dict = PyDict :: new ( py) ;
133- dict. set_item ( "protocol" , self . 0 . protocol ( ) ) . unwrap ( ) ;
134- dict. set_item ( "username" , self . 0 . username ( ) ) . unwrap ( ) ;
135- dict. set_item ( "password" , self . 0 . password ( ) ) . unwrap ( ) ;
136- dict. set_item ( "hostname" , self . 0 . hostname ( ) ) . unwrap ( ) ;
137- dict. set_item ( "port" , self . 0 . port ( ) ) . unwrap ( ) ;
138- dict. set_item ( "pathname" , self . 0 . pathname ( ) ) . unwrap ( ) ;
139- dict. set_item ( "search" , self . 0 . search ( ) ) . unwrap ( ) ;
140- dict. set_item ( "hash" , self . 0 . hash ( ) ) . unwrap ( ) ;
141- dict. set_item ( "hasRegExpGroups" , self . 0 . has_regexp_groups ( ) )
142- . unwrap ( ) ;
143- format ! ( "URLPattern({})" , dict)
133+ dict. set_item ( "protocol" , self . 0 . protocol ( ) ) ?;
134+ dict. set_item ( "username" , self . 0 . username ( ) ) ?;
135+ dict. set_item ( "password" , self . 0 . password ( ) ) ?;
136+ dict. set_item ( "hostname" , self . 0 . hostname ( ) ) ?;
137+ dict. set_item ( "port" , self . 0 . port ( ) ) ?;
138+ dict. set_item ( "pathname" , self . 0 . pathname ( ) ) ?;
139+ dict. set_item ( "search" , self . 0 . search ( ) ) ?;
140+ dict. set_item ( "hash" , self . 0 . hash ( ) ) ?;
141+ dict. set_item ( "hasRegExpGroups" , self . 0 . has_regexp_groups ( ) ) ?;
142+ Ok ( format ! ( "URLPattern({})" , dict) )
144143 }
145144
146145 #[ pyo3( signature = ( input=None , baseURL=None ) ) ]
@@ -415,7 +414,7 @@ struct UrlPatternResult<'py> {
415414impl < ' py > IntoPyObject < ' py > for UrlPatternResult < ' py > {
416415 type Target = PyDict ;
417416 type Output = Bound < ' py , Self :: Target > ;
418- type Error = std :: convert :: Infallible ;
417+ type Error = PyErr ;
419418
420419 fn into_pyobject ( self , py : Python < ' py > ) -> Result < Self :: Output , Self :: Error > {
421420 let dict = PyDict :: new ( py) ;
@@ -424,23 +423,23 @@ impl<'py> IntoPyObject<'py> for UrlPatternResult<'py> {
424423 for input in self . inputs {
425424 match input {
426425 UrlPatternInput :: String ( string) => {
427- inputs. append ( string) . unwrap ( ) ;
426+ inputs. append ( string) ? ;
428427 }
429428 UrlPatternInput :: Init ( init) => {
430- inputs. append ( init) . unwrap ( ) ;
429+ inputs. append ( init) ? ;
431430 }
432431 }
433432 }
434433
435- dict. set_item ( "inputs" , inputs) . unwrap ( ) ;
436- dict. set_item ( "protocol" , self . protocol ) . unwrap ( ) ;
437- dict. set_item ( "username" , self . username ) . unwrap ( ) ;
438- dict. set_item ( "password" , self . password ) . unwrap ( ) ;
439- dict. set_item ( "hostname" , self . hostname ) . unwrap ( ) ;
440- dict. set_item ( "port" , self . port ) . unwrap ( ) ;
441- dict. set_item ( "pathname" , self . pathname ) . unwrap ( ) ;
442- dict. set_item ( "search" , self . search ) . unwrap ( ) ;
443- dict. set_item ( "hash" , self . hash ) . unwrap ( ) ;
434+ dict. set_item ( "inputs" , inputs) ? ;
435+ dict. set_item ( "protocol" , self . protocol ) ? ;
436+ dict. set_item ( "username" , self . username ) ? ;
437+ dict. set_item ( "password" , self . password ) ? ;
438+ dict. set_item ( "hostname" , self . hostname ) ? ;
439+ dict. set_item ( "port" , self . port ) ? ;
440+ dict. set_item ( "pathname" , self . pathname ) ? ;
441+ dict. set_item ( "search" , self . search ) ? ;
442+ dict. set_item ( "hash" , self . hash ) ? ;
444443 Ok ( dict. into_bound ( ) )
445444 }
446445}
0 commit comments