@@ -241,6 +241,11 @@ impl<'a> TableBindGenerator<'a> {
241241 TypeKind :: SimpleType ( SimpleType :: Integer ( IntegerType :: U8 ) ) => {
242242 format ! ( "PyBytes::new(py, &flat_t.{field_name}).unbind()" )
243243 }
244+ TypeKind :: SimpleType ( SimpleType :: Enum ( _) ) => {
245+ format ! (
246+ "PyList::new(py, flat_t.{field_name}.iter().copied()).unwrap().unbind()"
247+ )
248+ }
244249 TypeKind :: Table ( idx) | TypeKind :: SimpleType ( SimpleType :: Struct ( idx) ) => {
245250 let ( path, _) = self . all_items . get_index ( idx. 0 ) . unwrap ( ) ;
246251 let type_name = path. 0 . last ( ) . unwrap ( ) ;
@@ -353,6 +358,11 @@ impl<'a> TableBindGenerator<'a> {
353358 TypeKind :: SimpleType ( SimpleType :: Integer ( IntegerType :: U8 ) ) => {
354359 format ! ( "py_type.{field_name}.as_bytes(py).to_vec()" )
355360 }
361+ TypeKind :: SimpleType ( SimpleType :: Enum ( _) ) => {
362+ format ! (
363+ "py_type.{field_name}.bind_borrowed(py).iter().map(|x| x.extract::<u8>().unwrap().try_into().unwrap()).collect()"
364+ )
365+ }
356366 TypeKind :: Table ( _) | TypeKind :: SimpleType ( SimpleType :: Struct ( _) ) => {
357367 format ! (
358368 "py_type.{field_name}.bind_borrowed(py).iter().map(|x| crate::from_pyany_into(py, x)).collect()"
@@ -460,7 +470,12 @@ impl<'a> TableBindGenerator<'a> {
460470 SimpleType :: Enum ( idx) => {
461471 let ( path, _) = self . all_items . get_index ( idx. 0 ) . unwrap ( ) ;
462472 let name = path. 0 . last ( ) . unwrap ( ) ;
463- Cow :: Owned ( format ! ( "super::{name}" ) )
473+
474+ Cow :: Owned ( if matches ! ( field_info. assign_mode, AssignMode :: Optional ) {
475+ format ! ( "Option<super::{name}>" )
476+ } else {
477+ format ! ( "super::{name}" )
478+ } )
464479 }
465480 SimpleType :: Struct ( idx) => {
466481 let ( path, _) = self . all_items . get_index ( idx. 0 ) . unwrap ( ) ;
@@ -684,7 +699,15 @@ impl<'a> TableBindGenerator<'a> {
684699 write_fmt ! ( self , " self.{field_name}," ) ;
685700 }
686701 SimpleType :: Enum ( _) => {
687- write_fmt ! ( self , " self.{field_name}.__repr__()," )
702+ if matches ! ( field_info. assign_mode, AssignMode :: Optional ) {
703+ write_fmt ! ( self , " self.{field_name}.as_ref()" ) ;
704+ write_str ! (
705+ self ,
706+ " .map_or_else(crate::none_str, |x| x.__repr__()),"
707+ ) ;
708+ } else {
709+ write_fmt ! ( self , " self.{field_name}.__repr__()," ) ;
710+ }
688711 }
689712 } ,
690713 TypeKind :: String => {
@@ -708,9 +731,9 @@ impl<'a> TableBindGenerator<'a> {
708731 AssignMode :: Optional => {
709732 write_fmt ! ( self , " self.{field_name}" ) ;
710733 write_str ! ( self , " .as_ref()" ) ;
711- write_str ! ( self , " .map_or_else(crate::none_str, |x| { " ) ;
734+ write_str ! ( self , " .map_or_else(crate::none_str, |x| " ) ;
712735 write_str ! ( self , " x.borrow(py).__repr__(py)" ) ;
713- write_str ! ( self , " } )," ) ;
736+ write_str ! ( self , " )," ) ;
714737 }
715738 _ => {
716739 write_fmt ! (
@@ -765,6 +788,14 @@ impl<'a> TableBindGenerator<'a> {
765788 " .map(|x| x.cast_into::<super::{name}>().unwrap().borrow().__repr__(py))"
766789 ) ;
767790 }
791+ SimpleType :: Enum ( idx) => {
792+ let ( path, _) = self . all_items . get_index ( idx. 0 ) . unwrap ( ) ;
793+ let name = path. 0 . last ( ) . unwrap ( ) ;
794+ write_str ! ( self , ".bind_borrowed(py).iter()" ) ;
795+ write_str ! ( self , ".map(|x| x.extract::<u8>().unwrap())" ) ;
796+ write_fmt ! ( self , ".map(|x| super::{name}::try_from(x).unwrap())" ) ;
797+ write_str ! ( self , ".map(|x| x.__repr__())" ) ;
798+ }
768799 _ => {
769800 write_str ! ( self , " .iter()" ) ;
770801 write_str ! ( self , " .map(ToString::to_string)" ) ;
0 commit comments