@@ -4,7 +4,7 @@ use crate::fields::base::Field;
44use crate :: fields:: base:: FieldTrait ;
55use pyo3:: intern;
66use pyo3:: prelude:: * ;
7- use pyo3:: types:: { PyDict , PyList } ;
7+ use pyo3:: types:: PyDict ;
88use std:: collections:: HashMap ;
99
1010#[ pyclass( subclass) ]
@@ -86,15 +86,20 @@ impl_py_methods!(Schema, required, { fields: HashMap<String, Field>, context: Ha
8686 }
8787
8888 if let Some ( true ) = many {
89- let pylist = instance. downcast:: <PyList >( ) ?;
90- let mut results: Vec <PyObject > = Vec :: with_capacity( pylist. len( ) ) ;
91- for inst in pylist. iter( ) {
92- let serialized = self . serialize_one( py, inst, parent. clone( ) ) ?;
93- results. push( serialized) ;
89+ if let Ok ( iter) = instance. iter( ) {
90+ let mut results: Vec <PyObject > = Vec :: new( ) ;
91+ for inst in iter {
92+ let serialized = self . serialize_one( py, inst?, parent. clone( ) ) ?;
93+ results. push( serialized) ;
94+ }
95+ return Ok ( results. into_py( py) ) ;
96+ } else {
97+ return Err (
98+ pyo3:: exceptions:: PyTypeError :: new_err( "Expected an iterable" ) ,
99+ ) ;
94100 }
95- return Ok ( results. into_py( py) ) ;
96101 }
97- self . serialize_one( py, instance, parent. clone( ) )
102+ self . serialize_one( py, instance, parent. clone( ) )
98103 }
99104 fn serialize_one(
100105 & self ,
0 commit comments