@@ -43,102 +43,72 @@ impl ComputedFields {
4343 self . 0 . len ( )
4444 }
4545
46- #[ allow( clippy:: too_many_arguments) ]
4746 pub fn to_python < ' py > (
4847 & self ,
4948 model : & Bound < ' py , PyAny > ,
5049 output_dict : & Bound < ' py , PyDict > ,
5150 filter : & SchemaFilter < isize > ,
52- include : Option < & Bound < ' py , PyAny > > ,
53- exclude : Option < & Bound < ' py , PyAny > > ,
5451 state : & mut SerializationState < ' py > ,
5552 extra : & Extra < ' _ , ' py > ,
5653 ) -> PyResult < ( ) > {
5754 self . serialize_fields (
5855 model,
5956 filter,
60- include,
61- exclude,
6257 state,
6358 extra,
6459 |e| e,
6560 |ComputedFieldToSerialize {
6661 computed_field,
6762 value,
68- include,
69- exclude,
7063 state,
7164 field_extra,
7265 } | {
7366 let key = match field_extra. serialize_by_alias_or ( computed_field. serialize_by_alias ) {
7467 true => computed_field. alias_py . bind ( model. py ( ) ) ,
7568 false => computed_field. property_name_py . bind ( model. py ( ) ) ,
7669 } ;
77- let value = computed_field. serializer . to_python (
78- & value,
79- include. as_ref ( ) ,
80- exclude. as_ref ( ) ,
81- state,
82- field_extra,
83- ) ?;
70+ let value = computed_field. serializer . to_python ( & value, state, field_extra) ?;
8471 output_dict. set_item ( key, value)
8572 } ,
8673 )
8774 }
8875
89- #[ allow( clippy:: too_many_arguments) ]
9076 pub fn serde_serialize < ' py , S : serde:: ser:: Serializer > (
9177 & self ,
9278 model : & Bound < ' py , PyAny > ,
9379 map : & mut S :: SerializeMap ,
9480 filter : & SchemaFilter < isize > ,
95- include : Option < & Bound < ' py , PyAny > > ,
96- exclude : Option < & Bound < ' py , PyAny > > ,
9781 state : & mut SerializationState < ' py > ,
9882 extra : & Extra < ' _ , ' py > ,
9983 ) -> Result < ( ) , S :: Error > {
10084 self . serialize_fields (
10185 model,
10286 filter,
103- include,
104- exclude,
10587 state,
10688 extra,
10789 py_err_se_err,
10890 |ComputedFieldToSerialize {
10991 computed_field,
11092 value,
111- include,
112- exclude,
11393 state,
11494 field_extra,
11595 } | {
11696 let key = match field_extra. serialize_by_alias_or ( computed_field. serialize_by_alias ) {
11797 true => & computed_field. alias ,
11898 false => & computed_field. property_name ,
11999 } ;
120- let s = PydanticSerializer :: new (
121- & value,
122- & computed_field. serializer ,
123- include. as_ref ( ) ,
124- exclude. as_ref ( ) ,
125- state,
126- field_extra,
127- ) ;
100+ let s = PydanticSerializer :: new ( & value, & computed_field. serializer , state, field_extra) ;
128101 map. serialize_entry ( key, & s)
129102 } ,
130103 )
131104 }
132105
133106 /// Iterate each field for serialization, filtering on
134107 /// `include` and `exclude` if provided.
135- #[ allow( clippy:: too_many_arguments) ]
136108 fn serialize_fields < ' a , ' py , E > (
137109 & ' a self ,
138110 model : & ' a Bound < ' py , PyAny > ,
139111 filter : & ' a SchemaFilter < isize > ,
140- include : Option < & ' a Bound < ' py , PyAny > > ,
141- exclude : Option < & ' a Bound < ' py , PyAny > > ,
142112 state : & mut SerializationState < ' py > ,
143113 extra : & ' a Extra < ' _ , ' py > ,
144114 convert_error : impl FnOnce ( PyErr ) -> E ,
@@ -151,7 +121,7 @@ impl ComputedFields {
151121
152122 for computed_field in & self . 0 {
153123 let property_name_py = computed_field. property_name_py . bind ( model. py ( ) ) ;
154- let ( next_include, next_exclude) = match filter. key_filter ( property_name_py, include , exclude ) {
124+ let ( next_include, next_exclude) = match filter. key_filter ( property_name_py, state ) {
155125 Ok ( Some ( ( next_include, next_exclude) ) ) => ( next_include, next_exclude) ,
156126 Ok ( None ) => continue ,
157127 Err ( e) => return Err ( convert_error ( e) ) ,
@@ -173,11 +143,10 @@ impl ComputedFields {
173143
174144 let field_name = FieldName :: from ( computed_field. property_name_py . bind ( model. py ( ) ) . clone ( ) ) ;
175145 let state = & mut state. scoped_set ( |s| & mut s. field_name , Some ( field_name) ) ;
146+ let state = & mut state. scoped_include_exclude ( next_include, next_exclude) ;
176147 serialize ( ComputedFieldToSerialize {
177148 computed_field,
178149 value,
179- include : next_include,
180- exclude : next_exclude,
181150 state,
182151 field_extra : extra,
183152 } ) ?;
@@ -189,8 +158,6 @@ impl ComputedFields {
189158struct ComputedFieldToSerialize < ' a , ' slf , ' py > {
190159 computed_field : & ' a ComputedField ,
191160 value : Bound < ' py , PyAny > ,
192- include : Option < Bound < ' py , PyAny > > ,
193- exclude : Option < Bound < ' py , PyAny > > ,
194161 state : & ' slf mut SerializationState < ' py > ,
195162 field_extra : & ' slf Extra < ' a , ' py > ,
196163}
0 commit comments