@@ -9,12 +9,10 @@ use num_enum::TryFromPrimitive;
99use strum_macros:: { EnumCount , EnumIter } ;
1010use thiserror:: Error ;
1111
12- // PyO3 imports (will only be used if the feature is enabled)
12+ // Conditional imports for Python bindings
1313#[ cfg( feature = "python_bindings" ) ]
14- use pyo3:: prelude:: * ;
14+ use pyo3:: { Bound , prelude:: * , types :: PyBytes } ;
1515#[ cfg( feature = "python_bindings" ) ]
16- use pyo3:: types:: PyBytes ;
17- #[ cfg_attr( not( feature = "python_bindings" ) , allow( unused_imports) ) ]
1816use std:: io:: Cursor ;
1917
2018#[ derive( Debug , Error ) ]
@@ -194,14 +192,14 @@ impl PyPNGImage {
194192 fn as_i8 ( & self ) -> PyResult < Py < PyBytes > > {
195193 let mut buf = Vec :: new ( ) ;
196194 self . img . as_i8 ( & mut buf) ?;
197- let py = unsafe { Python :: assume_gil_acquired ( ) } ;
195+ let py = unsafe { Python :: assume_attached ( ) } ;
198196 Ok ( PyBytes :: new ( py, & buf) . into ( ) )
199197 }
200198
201199 fn as_rgba16 ( & self ) -> PyResult < Py < PyBytes > > {
202200 let mut buf = Vec :: new ( ) ;
203201 self . img . as_rgba16 ( & mut buf) ?;
204- let py = unsafe { Python :: assume_gil_acquired ( ) } ;
202+ let py = unsafe { Python :: assume_attached ( ) } ;
205203 Ok ( PyBytes :: new ( py, & buf) . into ( ) )
206204 }
207205}
0 commit comments