@@ -19,7 +19,6 @@ use crate::serializers::type_serializers;
1919use crate :: serializers:: type_serializers:: format:: serialize_via_str;
2020use crate :: serializers:: SerializationState ;
2121use crate :: tools:: { extract_int, py_err, safe_repr} ;
22- use crate :: url:: { PyMultiHostUrl , PyUrl } ;
2322
2423use super :: config:: InfNanMode ;
2524use super :: errors:: SERIALIZATION_ERR_MARKER ;
@@ -168,7 +167,13 @@ pub(crate) fn infer_to_python_known<'py>(
168167 let either_delta = EitherTimedelta :: try_from ( value) ?;
169168 state. config . temporal_mode . timedelta_to_json ( value. py ( ) , either_delta) ?
170169 }
171- ObType :: Url | ObType :: MultiHostUrl | ObType :: Path => serialize_via_str ( value, serialize_to_python ( ) ) ?,
170+ ObType :: Url
171+ | ObType :: MultiHostUrl
172+ | ObType :: Path
173+ | ObType :: Ipv4Address
174+ | ObType :: Ipv6Address
175+ | ObType :: Ipv4Network
176+ | ObType :: Ipv6Network => serialize_via_str ( value, serialize_to_python ( ) ) ?,
172177 ObType :: Uuid => {
173178 let uuid = super :: type_serializers:: uuid:: uuid_to_string ( value) ?;
174179 uuid. into_py_any ( py) ?
@@ -413,9 +418,13 @@ pub(crate) fn infer_serialize_known<'py, S: Serializer>(
413418 let either_delta = EitherTimedelta :: try_from ( value) . map_err ( py_err_se_err) ?;
414419 state. config . temporal_mode . timedelta_serialize ( either_delta, serializer)
415420 }
416- ObType :: Url | ObType :: MultiHostUrl | ObType :: Path => {
417- serialize_via_str ( value, serialize_to_json ( serializer) ) . map_err ( unwrap_ser_error)
418- }
421+ ObType :: Url
422+ | ObType :: MultiHostUrl
423+ | ObType :: Path
424+ | ObType :: Ipv4Address
425+ | ObType :: Ipv6Address
426+ | ObType :: Ipv4Network
427+ | ObType :: Ipv6Network => serialize_via_str ( value, serialize_to_json ( serializer) ) . map_err ( unwrap_ser_error) ,
419428 ObType :: PydanticSerializable => {
420429 call_pydantic_serializer ( value, state, serialize_to_json ( serializer) ) . map_err ( unwrap_ser_error)
421430 }
@@ -546,13 +555,15 @@ pub(crate) fn infer_json_key_known<'a, 'py>(
546555 let either_delta = EitherTimedelta :: try_from ( key) ?;
547556 state. config . temporal_mode . timedelta_json_key ( & either_delta)
548557 }
549- ObType :: Url => {
550- let py_url: PyUrl = key. extract ( ) ?;
551- Ok ( Cow :: Owned ( py_url. __str__ ( key. py ( ) ) . to_string ( ) ) )
552- }
553- ObType :: MultiHostUrl => {
554- let py_url: PyMultiHostUrl = key. extract ( ) ?;
555- Ok ( Cow :: Owned ( py_url. __str__ ( key. py ( ) ) ) )
558+ ObType :: Url
559+ | ObType :: MultiHostUrl
560+ | ObType :: Path
561+ | ObType :: Ipv4Address
562+ | ObType :: Ipv6Address
563+ | ObType :: Ipv4Network
564+ | ObType :: Ipv6Network => {
565+ // FIXME it would be nice to have a "PyCow" which carries ownership of the Python type too
566+ Ok ( Cow :: Owned ( key. str ( ) ?. to_string_lossy ( ) . into_owned ( ) ) )
556567 }
557568 ObType :: Tuple => {
558569 let mut key_build = super :: type_serializers:: tuple:: KeyBuilder :: new ( ) ;
@@ -574,10 +585,6 @@ pub(crate) fn infer_json_key_known<'a, 'py>(
574585 let k = key. getattr ( intern ! ( key. py( ) , "value" ) ) ?;
575586 infer_json_key ( & k, state) . map ( |cow| Cow :: Owned ( cow. into_owned ( ) ) )
576587 }
577- ObType :: Path => {
578- // FIXME it would be nice to have a "PyCow" which carries ownership of the Python type too
579- Ok ( Cow :: Owned ( key. str ( ) ?. to_string_lossy ( ) . into_owned ( ) ) )
580- }
581588 ObType :: Complex => {
582589 let v = key. downcast :: < PyComplex > ( ) ?;
583590 Ok ( type_serializers:: complex:: complex_to_str ( v) . into ( ) )
0 commit comments