File tree Expand file tree Collapse file tree 2 files changed +5
-11
lines changed Expand file tree Collapse file tree 2 files changed +5
-11
lines changed Original file line number Diff line number Diff line change @@ -131,7 +131,7 @@ pub(crate) fn infer_to_python_known(
131
131
v. into_py ( py)
132
132
}
133
133
ObType :: Decimal => value. to_string ( ) . into_py ( py) ,
134
- ObType :: StrSubclass => value. downcast :: < PyString > ( ) ?. to_str ( ) ?. into_py ( py ) ,
134
+ ObType :: StrSubclass => PyString :: new_bound ( py , value. downcast :: < PyString > ( ) ?. to_str ( ) ?) . into ( ) ,
135
135
ObType :: Bytes => extra
136
136
. config
137
137
. bytes_mode
@@ -609,16 +609,11 @@ pub(crate) fn infer_json_key_known<'a>(
609
609
}
610
610
ObType :: Decimal => Ok ( Cow :: Owned ( key. to_string ( ) ) ) ,
611
611
ObType :: Bool => super :: type_serializers:: simple:: bool_json_key ( key) ,
612
- ObType :: Str | ObType :: StrSubclass => {
613
- let py_str = key. downcast :: < PyString > ( ) ?;
614
- Ok ( Cow :: Owned ( py_str. to_str ( ) ?. to_string ( ) ) )
615
- }
612
+ ObType :: Str | ObType :: StrSubclass => key. downcast :: < PyString > ( ) ?. to_cow ( ) ,
616
613
ObType :: Bytes => extra
617
614
. config
618
615
. bytes_mode
619
- . bytes_to_string ( key. py ( ) , key. downcast :: < PyBytes > ( ) ?. as_bytes ( ) )
620
- // FIXME it would be nice to have a "PyCow" which carries ownership of the Python type too
621
- . map ( |s| Cow :: Owned ( s. into_owned ( ) ) ) ,
616
+ . bytes_to_string ( key. py ( ) , key. downcast :: < PyBytes > ( ) ?. as_bytes ( ) ) ,
622
617
ObType :: Bytearray => {
623
618
let py_byte_array = key. downcast :: < PyByteArray > ( ) ?;
624
619
// Safety: the GIL is held while serialize_bytes is running; it doesn't run
Original file line number Diff line number Diff line change @@ -70,16 +70,15 @@ impl BuildSerializer for FormatSerializer {
70
70
) -> PyResult < CombinedSerializer > {
71
71
let py = schema. py ( ) ;
72
72
let formatting_string: Bound < ' _ , PyString > = schema. get_as_req ( intern ! ( py, "formatting_string" ) ) ?;
73
- let formatting_string = formatting_string. to_str ( ) ?;
74
- if formatting_string. is_empty ( ) {
73
+ if formatting_string. is_empty ( ) ? {
75
74
ToStringSerializer :: build ( schema, config, definitions)
76
75
} else {
77
76
Ok ( Self {
78
77
format_func : py
79
78
. import_bound ( intern ! ( py, "builtins" ) ) ?
80
79
. getattr ( intern ! ( py, "format" ) ) ?
81
80
. into_py ( py) ,
82
- formatting_string : PyString :: new_bound ( py , formatting_string) . into ( ) ,
81
+ formatting_string : formatting_string. unbind ( ) ,
83
82
when_used : WhenUsed :: new ( schema, WhenUsed :: JsonUnlessNone ) ?,
84
83
}
85
84
. into ( ) )
You can’t perform that action at this time.
0 commit comments