@@ -12,8 +12,9 @@ use crate::tools::SchemaDict;
12
12
use super :: simple:: to_str_json_key;
13
13
use super :: {
14
14
infer_json_key, infer_serialize, infer_to_python, BuildSerializer , CombinedSerializer , Extra , IsType , ObType ,
15
- SerMode , TypeSerializer ,
15
+ SerCheck , SerMode , TypeSerializer ,
16
16
} ;
17
+ use crate :: serializers:: errors:: PydanticSerializationUnexpectedValue ;
17
18
18
19
#[ derive( Debug ) ]
19
20
pub struct FloatSerializer {
@@ -73,12 +74,15 @@ impl TypeSerializer for FloatSerializer {
73
74
let py = value. py ( ) ;
74
75
match extra. ob_type_lookup . is_type ( value, ObType :: Float ) {
75
76
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
+ } ,
82
86
} ,
83
87
IsType :: False => {
84
88
extra. warnings . on_fallback_py ( self . get_name ( ) , value, extra) ?;
0 commit comments