@@ -25,7 +25,7 @@ macro_rules! define_exception_fn {
2525 pub fn $fn_name( & self , msg: impl Into <String >) -> PyBaseExceptionRef
2626 {
2727 let err = self . ctx. exceptions. $attr. to_owned( ) ;
28- self . new_exception_msg( err, msg)
28+ self . new_exception_msg( err, msg. into ( ) )
2929 }
3030 } ;
3131}
@@ -117,12 +117,8 @@ impl VirtualMachine {
117117 /// type is passed in, it may not be fully initialized; try using
118118 /// [`vm.invoke_exception()`][Self::invoke_exception] or
119119 /// [`exceptions::ExceptionCtor`][crate::exceptions::ExceptionCtor] instead.
120- pub fn new_exception_msg (
121- & self ,
122- exc_type : PyTypeRef ,
123- msg : impl Into < String > ,
124- ) -> PyBaseExceptionRef {
125- self . new_exception ( exc_type, vec ! [ self . ctx. new_str( msg. into( ) ) . into( ) ] )
120+ pub fn new_exception_msg ( & self , exc_type : PyTypeRef , msg : String ) -> PyBaseExceptionRef {
121+ self . new_exception ( exc_type, vec ! [ self . ctx. new_str( msg) . into( ) ] )
126122 }
127123
128124 /// Instantiate an exception with `msg` as the only argument and `dict` for object
@@ -133,14 +129,14 @@ impl VirtualMachine {
133129 pub fn new_exception_msg_dict (
134130 & self ,
135131 exc_type : PyTypeRef ,
136- msg : impl Into < String > ,
132+ msg : String ,
137133 dict : PyDictRef ,
138134 ) -> PyBaseExceptionRef {
139135 PyRef :: new_ref (
140136 // TODO: this constructor might be invalid, because multiple
141137 // exception (even builtin ones) are using custom constructors,
142138 // see `OSError` as an example:
143- PyBaseException :: new ( vec ! [ self . ctx. new_str( msg. into ( ) ) . into( ) ] , self ) ,
139+ PyBaseException :: new ( vec ! [ self . ctx. new_str( msg) . into( ) ] , self ) ,
144140 exc_type,
145141 Some ( dict) ,
146142 )
@@ -162,7 +158,7 @@ impl VirtualMachine {
162158
163159 pub fn new_name_error ( & self , msg : impl Into < String > , name : PyStrRef ) -> PyBaseExceptionRef {
164160 let name_error_type = self . ctx . exceptions . name_error . to_owned ( ) ;
165- let name_error = self . new_exception_msg ( name_error_type, msg) ;
161+ let name_error = self . new_exception_msg ( name_error_type, msg. into ( ) ) ;
166162 name_error. as_object ( ) . set_attr ( "name" , name, self ) . unwrap ( ) ;
167163 name_error
168164 }
@@ -476,7 +472,7 @@ impl VirtualMachine {
476472
477473 pub fn new_import_error ( & self , msg : impl Into < String > , name : PyStrRef ) -> PyBaseExceptionRef {
478474 let import_error = self . ctx . exceptions . import_error . to_owned ( ) ;
479- let exc = self . new_exception_msg ( import_error, msg) ;
475+ let exc = self . new_exception_msg ( import_error, msg. into ( ) ) ;
480476 exc. as_object ( ) . set_attr ( "name" , name, self ) . unwrap ( ) ;
481477 exc
482478 }
0 commit comments