@@ -31,11 +31,9 @@ use crate::vm::VirtualMachine;
3131use crate :: stdlib:: io:: io_open;
3232
3333fn builtin_abs ( x : PyObjectRef , vm : & VirtualMachine ) -> PyResult {
34- let method = vm. get_method_or_type_error (
35- x. clone ( ) ,
36- "__abs__" ,
37- format ! ( "bad operand type for abs(): '{}'" , x. class( ) . name) ,
38- ) ?;
34+ let method = vm. get_method_or_type_error ( x. clone ( ) , "__abs__" , || {
35+ format ! ( "bad operand type for abs(): '{}'" , x. class( ) . name)
36+ } ) ?;
3937 vm. invoke ( method, PyFuncArgs :: new ( vec ! [ ] , vec ! [ ] ) )
4038}
4139
@@ -369,11 +367,9 @@ fn builtin_iter(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
369367
370368fn builtin_len ( vm : & VirtualMachine , args : PyFuncArgs ) -> PyResult {
371369 arg_check ! ( vm, args, required = [ ( obj, None ) ] ) ;
372- let method = vm. get_method_or_type_error (
373- obj. clone ( ) ,
374- "__len__" ,
375- format ! ( "object of type '{}' has no len()" , obj. class( ) . name) ,
376- ) ?;
370+ let method = vm. get_method_or_type_error ( obj. clone ( ) , "__len__" , || {
371+ format ! ( "object of type '{}' has no len()" , obj. class( ) . name)
372+ } ) ?;
377373 vm. invoke ( method, PyFuncArgs :: default ( ) )
378374}
379375
@@ -671,11 +667,9 @@ fn builtin_reversed(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
671667 arg_check ! ( vm, args, required = [ ( obj, None ) ] ) ;
672668
673669 // TODO: fallback to using __len__ and __getitem__, if object supports sequence protocol
674- let method = vm. get_method_or_type_error (
675- obj. clone ( ) ,
676- "__reversed__" ,
677- format ! ( "argument to reversed() must be a sequence" ) ,
678- ) ?;
670+ let method = vm. get_method_or_type_error ( obj. clone ( ) , "__reversed__" , || {
671+ format ! ( "argument to reversed() must be a sequence" )
672+ } ) ?;
679673 vm. invoke ( method, PyFuncArgs :: default ( ) )
680674}
681675
0 commit comments