@@ -77,7 +77,9 @@ impl PythonBindGenerator {
7777 if bind_type == PythonBindType :: Union {
7878 file_contents. push ( Cow :: Borrowed ( "use pyo3::{pyclass, pymethods};" ) ) ;
7979 } else {
80- file_contents. push ( Cow :: Borrowed ( "use pyo3::{pyclass, pymethods, types::PyBytes, Python};" ) ) ;
80+ file_contents. push ( Cow :: Borrowed (
81+ "use pyo3::{pyclass, pymethods, types::PyBytes, Bound, Python};" ,
82+ ) ) ;
8183 }
8284
8385 file_contents. push ( Cow :: Borrowed ( "" ) ) ;
@@ -917,7 +919,7 @@ impl PythonBindGenerator {
917919 }
918920
919921 fn generate_pack_method ( & mut self ) {
920- self . write_str ( " fn pack<'p >(&self, py: Python<'p >) -> &'p PyBytes {" ) ;
922+ self . write_str ( " fn pack<'py >(&self, py: Python<'py >) -> Bound<'py, PyBytes> {" ) ;
921923 if self . has_complex_pack {
922924 self . write_str ( " let size = self.get_size();" ) ;
923925 self . write_str ( " let mut builder = FlatBufferBuilder::with_capacity(size);" ) ;
@@ -935,13 +937,13 @@ impl PythonBindGenerator {
935937 self . write_str ( " let offset = flat_t.pack(&mut builder);" ) ;
936938 self . write_str ( " builder.finish(offset, None);" ) ;
937939 self . write_str ( "" ) ;
938- self . write_str ( " PyBytes::new (py, builder.finished_data())" ) ;
940+ self . write_str ( " PyBytes::new_bound (py, builder.finished_data())" ) ;
939941 } else if self . bind_type == PythonBindType :: Enum {
940- self . write_str ( " PyBytes::new (py, &[flat_t.0])" ) ;
942+ self . write_str ( " PyBytes::new_bound (py, &[flat_t.0])" ) ;
941943 } else {
942944 self . write_str ( " let item = flat_t.pack();" ) ;
943945 self . write_str ( "" ) ;
944- self . write_str ( " PyBytes::new (py, &item.0)" ) ;
946+ self . write_str ( " PyBytes::new_bound (py, &item.0)" ) ;
945947 }
946948
947949 self . write_str ( " }" ) ;
0 commit comments