@@ -12,8 +12,9 @@ use crate::tools::SchemaDict;
1212use super :: simple:: to_str_json_key;
1313use super :: {
1414 infer_json_key, infer_serialize, infer_to_python, BuildSerializer , CombinedSerializer , Extra , IsType , ObType ,
15- SerMode , TypeSerializer ,
15+ SerCheck , SerMode , TypeSerializer ,
1616} ;
17+ use crate :: serializers:: errors:: PydanticSerializationUnexpectedValue ;
1718
1819#[ derive( Debug ) ]
1920pub struct FloatSerializer {
@@ -73,12 +74,15 @@ impl TypeSerializer for FloatSerializer {
7374 let py = value. py ( ) ;
7475 match extra. ob_type_lookup . is_type ( value, ObType :: Float ) {
7576 IsType :: Exact => Ok ( value. into_py ( py) ) ,
76- IsType :: Subclass => match extra. mode {
77- SerMode :: Json => {
78- let rust_value = value. extract :: < f64 > ( ) ?;
79- Ok ( rust_value. to_object ( py) )
80- }
81- _ => infer_to_python ( value, include, exclude, extra) ,
77+ IsType :: Subclass => match extra. check {
78+ SerCheck :: Strict => Err ( PydanticSerializationUnexpectedValue :: new_err ( None ) ) ,
79+ SerCheck :: Lax | SerCheck :: None => match extra. mode {
80+ SerMode :: Json => {
81+ let rust_value = value. extract :: < f64 > ( ) ?;
82+ Ok ( rust_value. to_object ( py) )
83+ }
84+ _ => infer_to_python ( value, include, exclude, extra) ,
85+ } ,
8286 } ,
8387 IsType :: False => {
8488 extra. warnings . on_fallback_py ( self . get_name ( ) , value, extra) ?;
0 commit comments