@@ -11,6 +11,7 @@ use pyo3::PyTraverseError;
1111use pyo3:: types:: PyString ;
1212
1313use crate :: definitions:: DefinitionsBuilder ;
14+ use crate :: py_gc:: PyGcTraverse ;
1415use crate :: serializers:: SerializationState ;
1516use crate :: tools:: SchemaDict ;
1617use crate :: tools:: { function_name, py_err, py_error_type} ;
@@ -437,6 +438,11 @@ pub(crate) struct SerializationCallable {
437438 filter : AnyFilter ,
438439}
439440
441+ impl_py_gc_traverse ! ( SerializationCallable {
442+ serializer,
443+ extra_owned
444+ } ) ;
445+
440446impl SerializationCallable {
441447 pub fn new ( serializer : & Arc < CombinedSerializer > , state : & SerializationState < ' _ , ' _ > ) -> Self {
442448 Self {
@@ -447,16 +453,7 @@ impl SerializationCallable {
447453 }
448454
449455 fn __traverse__ ( & self , visit : PyVisit < ' _ > ) -> Result < ( ) , PyTraverseError > {
450- if let Some ( model) = & self . extra_owned . model {
451- visit. call ( model) ?;
452- }
453- if let Some ( fallback) = & self . extra_owned . fallback {
454- visit. call ( fallback) ?;
455- }
456- if let Some ( context) = & self . extra_owned . context {
457- visit. call ( context) ?;
458- }
459- Ok ( ( ) )
456+ self . py_gc_traverse ( & visit)
460457 }
461458
462459 fn __clear__ ( & mut self ) {
@@ -542,6 +539,12 @@ struct SerializationInfo {
542539 serialize_as_any : bool ,
543540}
544541
542+ impl_py_gc_traverse ! ( SerializationInfo {
543+ include,
544+ exclude,
545+ context
546+ } ) ;
547+
545548impl SerializationInfo {
546549 fn new ( state : & SerializationState < ' _ , ' _ > , is_field_serializer : bool ) -> PyResult < Self > {
547550 let extra = & state. extra ;
@@ -584,16 +587,7 @@ impl SerializationInfo {
584587 }
585588
586589 fn __traverse__ ( & self , visit : PyVisit < ' _ > ) -> Result < ( ) , PyTraverseError > {
587- if let Some ( include) = & self . include {
588- visit. call ( include) ?;
589- }
590- if let Some ( exclude) = & self . exclude {
591- visit. call ( exclude) ?;
592- }
593- if let Some ( context) = & self . context {
594- visit. call ( context) ?;
595- }
596- Ok ( ( ) )
590+ self . py_gc_traverse ( & visit)
597591 }
598592
599593 fn __clear__ ( & mut self ) {
0 commit comments