@@ -16,7 +16,6 @@ use crate::serializers::SerializationState;
1616use crate :: tools:: SchemaDict ;
1717
1818use super :: errors:: py_err_se_err;
19- use super :: Extra ;
2019
2120#[ derive( Debug ) ]
2221pub ( super ) struct ComputedFields ( Vec < ComputedField > ) ;
@@ -48,26 +47,23 @@ impl ComputedFields {
4847 model : & Bound < ' py , PyAny > ,
4948 output_dict : & Bound < ' py , PyDict > ,
5049 filter : & SchemaFilter < isize > ,
51- state : & mut SerializationState < ' py > ,
52- extra : & Extra < ' _ , ' py > ,
50+ state : & mut SerializationState < ' _ , ' py > ,
5351 ) -> PyResult < ( ) > {
5452 self . serialize_fields (
5553 model,
5654 filter,
5755 state,
58- extra,
5956 |e| e,
6057 |ComputedFieldToSerialize {
6158 computed_field,
6259 value,
6360 state,
64- field_extra,
6561 } | {
66- let key = match field_extra . serialize_by_alias_or ( computed_field. serialize_by_alias ) {
62+ let key = match state . extra . serialize_by_alias_or ( computed_field. serialize_by_alias ) {
6763 true => computed_field. alias_py . bind ( model. py ( ) ) ,
6864 false => computed_field. property_name_py . bind ( model. py ( ) ) ,
6965 } ;
70- let value = computed_field. serializer . to_python ( & value, state, field_extra ) ?;
66+ let value = computed_field. serializer . to_python ( & value, state) ?;
7167 output_dict. set_item ( key, value)
7268 } ,
7369 )
@@ -78,44 +74,40 @@ impl ComputedFields {
7874 model : & Bound < ' py , PyAny > ,
7975 map : & mut S :: SerializeMap ,
8076 filter : & SchemaFilter < isize > ,
81- state : & mut SerializationState < ' py > ,
82- extra : & Extra < ' _ , ' py > ,
77+ state : & mut SerializationState < ' _ , ' py > ,
8378 ) -> Result < ( ) , S :: Error > {
8479 self . serialize_fields (
8580 model,
8681 filter,
8782 state,
88- extra,
8983 py_err_se_err,
9084 |ComputedFieldToSerialize {
9185 computed_field,
9286 value,
9387 state,
94- field_extra,
9588 } | {
96- let key = match field_extra . serialize_by_alias_or ( computed_field. serialize_by_alias ) {
89+ let key = match state . extra . serialize_by_alias_or ( computed_field. serialize_by_alias ) {
9790 true => & computed_field. alias ,
9891 false => & computed_field. property_name ,
9992 } ;
100- let s = PydanticSerializer :: new ( & value, & computed_field. serializer , state, field_extra ) ;
93+ let s = PydanticSerializer :: new ( & value, & computed_field. serializer , state) ;
10194 map. serialize_entry ( key, & s)
10295 } ,
10396 )
10497 }
10598
10699 /// Iterate each field for serialization, filtering on
107100 /// `include` and `exclude` if provided.
108- fn serialize_fields < ' a , ' py , E > (
109- & ' a self ,
110- model : & ' a Bound < ' py , PyAny > ,
111- filter : & ' a SchemaFilter < isize > ,
112- state : & mut SerializationState < ' py > ,
113- extra : & ' a Extra < ' _ , ' py > ,
101+ fn serialize_fields < ' py , E > (
102+ & self ,
103+ model : & Bound < ' py , PyAny > ,
104+ filter : & SchemaFilter < isize > ,
105+ state : & mut SerializationState < ' _ , ' py > ,
114106 convert_error : impl FnOnce ( PyErr ) -> E ,
115- mut serialize : impl for < ' slf > FnMut ( ComputedFieldToSerialize < ' a , ' slf , ' py > ) -> Result < ( ) , E > ,
107+ mut serialize : impl for <' slf , ' a > FnMut ( ComputedFieldToSerialize < ' slf , ' a , ' py > ) -> Result < ( ) , E > ,
116108 ) -> Result < ( ) , E > {
117109 // In round trip mode, exclude computed fields:
118- if extra. round_trip || extra. exclude_computed_fields {
110+ if state . extra . round_trip || state . extra . exclude_computed_fields {
119111 return Ok ( ( ) ) ;
120112 }
121113
@@ -133,7 +125,7 @@ impl ComputedFields {
133125 return Err ( convert_error ( e) ) ;
134126 }
135127 } ;
136- if extra. exclude_none && value. is_none ( ) {
128+ if state . extra . exclude_none && value. is_none ( ) {
137129 continue ;
138130 }
139131 let missing_sentinel = get_missing_sentinel_object ( model. py ( ) ) ;
@@ -148,18 +140,16 @@ impl ComputedFields {
148140 computed_field,
149141 value,
150142 state,
151- field_extra : extra,
152143 } ) ?;
153144 }
154145 Ok ( ( ) )
155146 }
156147}
157148
158- struct ComputedFieldToSerialize < ' a , ' slf , ' py > {
159- computed_field : & ' a ComputedField ,
149+ struct ComputedFieldToSerialize < ' slf , ' a , ' py > {
150+ computed_field : & ' slf ComputedField ,
160151 value : Bound < ' py , PyAny > ,
161- state : & ' slf mut SerializationState < ' py > ,
162- field_extra : & ' slf Extra < ' a , ' py > ,
152+ state : & ' slf mut SerializationState < ' a , ' py > ,
163153}
164154
165155#[ derive( Debug ) ]
0 commit comments