@@ -3,9 +3,9 @@ pub(crate) use math::make_module;
33#[ pymodule]
44mod math {
55 use crate :: vm:: {
6- builtins:: { try_bigint_to_f64, try_f64_to_bigint, PyFloat , PyInt , PyIntRef } ,
6+ builtins:: { try_bigint_to_f64, try_f64_to_bigint, PyFloat , PyInt , PyIntRef , PyStrInterned } ,
77 function:: { ArgIntoFloat , ArgIterable , Either , OptionalArg , PosArgs } ,
8- AsObject , PyObject , PyObjectRef , PyRef , PyResult , VirtualMachine ,
8+ identifier , AsObject , PyObject , PyObjectRef , PyRef , PyResult , VirtualMachine ,
99 } ;
1010 use num_bigint:: BigInt ;
1111 use num_traits:: { One , Signed , Zero } ;
@@ -430,25 +430,29 @@ mod math {
430430 }
431431 }
432432
433- fn try_magic_method ( func_name : & str , vm : & VirtualMachine , value : & PyObject ) -> PyResult {
433+ fn try_magic_method (
434+ func_name : & ' static PyStrInterned ,
435+ vm : & VirtualMachine ,
436+ value : & PyObject ,
437+ ) -> PyResult {
434438 let method = vm. get_method_or_type_error ( value. to_owned ( ) , func_name, || {
435439 format ! (
436440 "type '{}' doesn't define '{}' method" ,
437441 value. class( ) . name( ) ,
438- func_name,
442+ func_name. as_str ( ) ,
439443 )
440444 } ) ?;
441445 vm. invoke ( & method, ( ) )
442446 }
443447
444448 #[ pyfunction]
445449 fn trunc ( x : PyObjectRef , vm : & VirtualMachine ) -> PyResult {
446- try_magic_method ( " __trunc__" , vm, & x)
450+ try_magic_method ( identifier ! ( vm , __trunc__) , vm, & x)
447451 }
448452
449453 #[ pyfunction]
450454 fn ceil ( x : PyObjectRef , vm : & VirtualMachine ) -> PyResult {
451- let result_or_err = try_magic_method ( " __ceil__" , vm, & x) ;
455+ let result_or_err = try_magic_method ( identifier ! ( vm , __ceil__) , vm, & x) ;
452456 if result_or_err. is_err ( ) {
453457 if let Ok ( Some ( v) ) = x. try_to_f64 ( vm) {
454458 let v = try_f64_to_bigint ( v. ceil ( ) , vm) ?;
@@ -460,7 +464,7 @@ mod math {
460464
461465 #[ pyfunction]
462466 fn floor ( x : PyObjectRef , vm : & VirtualMachine ) -> PyResult {
463- let result_or_err = try_magic_method ( " __floor__" , vm, & x) ;
467+ let result_or_err = try_magic_method ( identifier ! ( vm , __floor__) , vm, & x) ;
464468 if result_or_err. is_err ( ) {
465469 if let Ok ( Some ( v) ) = x. try_to_f64 ( vm) {
466470 let v = try_f64_to_bigint ( v. floor ( ) , vm) ?;
0 commit comments