@@ -2038,10 +2038,9 @@ impl ExecutingFrame<'_> {
20382038 } else {
20392039 // Both merged cells (LOCAL|CELL) and non-merged cells get unbound local error
20402040 let name = self . localsplus_name ( localsplus_idx) ;
2041- vm. new_exception_msg (
2042- vm. ctx . exceptions . unbound_local_error . to_owned ( ) ,
2043- format ! ( "local variable '{name}' referenced before assignment" ) . into ( ) ,
2044- )
2041+ vm. new_unbound_local_error ( format ! (
2042+ "local variable '{name}' referenced before assignment"
2043+ ) )
20452044 }
20462045 }
20472046
@@ -2378,14 +2377,10 @@ impl ExecutingFrame<'_> {
23782377 let fastlocals = self . localsplus . fastlocals_mut ( ) ;
23792378 let idx = var_num. get ( arg) ;
23802379 if fastlocals[ idx] . is_none ( ) {
2381- return Err ( vm. new_exception_msg (
2382- vm. ctx . exceptions . unbound_local_error . to_owned ( ) ,
2383- format ! (
2384- "local variable '{}' referenced before assignment" ,
2385- self . code. varnames[ idx]
2386- )
2387- . into ( ) ,
2388- ) ) ;
2380+ return Err ( vm. new_unbound_local_error ( format ! (
2381+ "local variable '{}' referenced before assignment" ,
2382+ self . code. varnames[ idx]
2383+ ) ) ) ;
23892384 }
23902385 fastlocals[ idx] = None ;
23912386 Ok ( None )
@@ -2884,10 +2879,9 @@ impl ExecutingFrame<'_> {
28842879 varname : & ' static PyStrInterned ,
28852880 vm : & VirtualMachine ,
28862881 ) -> PyBaseExceptionRef {
2887- vm. new_exception_msg (
2888- vm. ctx . exceptions . unbound_local_error . to_owned ( ) ,
2889- format ! ( "local variable '{varname}' referenced before assignment" ) . into ( ) ,
2890- )
2882+ vm. new_unbound_local_error ( format ! (
2883+ "local variable '{varname}' referenced before assignment"
2884+ ) )
28912885 }
28922886 let idx = var_num. get ( arg) ;
28932887 let x = self . localsplus . fastlocals ( ) [ idx]
@@ -2910,14 +2904,10 @@ impl ExecutingFrame<'_> {
29102904 // (LoadFast in RustPython already does this check)
29112905 let idx = var_num. get ( arg) ;
29122906 let x = self . localsplus . fastlocals ( ) [ idx] . clone ( ) . ok_or_else ( || {
2913- vm. new_exception_msg (
2914- vm. ctx . exceptions . unbound_local_error . to_owned ( ) ,
2915- format ! (
2916- "local variable '{}' referenced before assignment" ,
2917- self . code. varnames[ idx]
2918- )
2919- . into ( ) ,
2920- )
2907+ vm. new_unbound_local_error ( format ! (
2908+ "local variable '{}' referenced before assignment" ,
2909+ self . code. varnames[ idx]
2910+ ) )
29212911 } ) ?;
29222912 self . push_value ( x) ;
29232913 Ok ( None )
@@ -2929,24 +2919,16 @@ impl ExecutingFrame<'_> {
29292919 let ( idx1, idx2) = oparg. indexes ( ) ;
29302920 let fastlocals = self . localsplus . fastlocals ( ) ;
29312921 let x1 = fastlocals[ idx1] . clone ( ) . ok_or_else ( || {
2932- vm. new_exception_msg (
2933- vm. ctx . exceptions . unbound_local_error . to_owned ( ) ,
2934- format ! (
2935- "local variable '{}' referenced before assignment" ,
2936- self . code. varnames[ idx1]
2937- )
2938- . into ( ) ,
2939- )
2922+ vm. new_unbound_local_error ( format ! (
2923+ "local variable '{}' referenced before assignment" ,
2924+ self . code. varnames[ idx1]
2925+ ) )
29402926 } ) ?;
29412927 let x2 = fastlocals[ idx2] . clone ( ) . ok_or_else ( || {
2942- vm. new_exception_msg (
2943- vm. ctx . exceptions . unbound_local_error . to_owned ( ) ,
2944- format ! (
2945- "local variable '{}' referenced before assignment" ,
2946- self . code. varnames[ idx2]
2947- )
2948- . into ( ) ,
2949- )
2928+ vm. new_unbound_local_error ( format ! (
2929+ "local variable '{}' referenced before assignment" ,
2930+ self . code. varnames[ idx2]
2931+ ) )
29502932 } ) ?;
29512933 self . push_value ( x1) ;
29522934 self . push_value ( x2) ;
@@ -2958,14 +2940,10 @@ impl ExecutingFrame<'_> {
29582940 Instruction :: LoadFastBorrow { var_num } => {
29592941 let idx = var_num. get ( arg) ;
29602942 let x = self . localsplus . fastlocals ( ) [ idx] . clone ( ) . ok_or_else ( || {
2961- vm. new_exception_msg (
2962- vm. ctx . exceptions . unbound_local_error . to_owned ( ) ,
2963- format ! (
2964- "local variable '{}' referenced before assignment" ,
2965- self . code. varnames[ idx]
2966- )
2967- . into ( ) ,
2968- )
2943+ vm. new_unbound_local_error ( format ! (
2944+ "local variable '{}' referenced before assignment" ,
2945+ self . code. varnames[ idx]
2946+ ) )
29692947 } ) ?;
29702948 self . push_value ( x) ;
29712949 Ok ( None )
@@ -2975,24 +2953,16 @@ impl ExecutingFrame<'_> {
29752953 let ( idx1, idx2) = oparg. indexes ( ) ;
29762954 let fastlocals = self . localsplus . fastlocals ( ) ;
29772955 let x1 = fastlocals[ idx1] . clone ( ) . ok_or_else ( || {
2978- vm. new_exception_msg (
2979- vm. ctx . exceptions . unbound_local_error . to_owned ( ) ,
2980- format ! (
2981- "local variable '{}' referenced before assignment" ,
2982- self . code. varnames[ idx1]
2983- )
2984- . into ( ) ,
2985- )
2956+ vm. new_unbound_local_error ( format ! (
2957+ "local variable '{}' referenced before assignment" ,
2958+ self . code. varnames[ idx1]
2959+ ) )
29862960 } ) ?;
29872961 let x2 = fastlocals[ idx2] . clone ( ) . ok_or_else ( || {
2988- vm. new_exception_msg (
2989- vm. ctx . exceptions . unbound_local_error . to_owned ( ) ,
2990- format ! (
2991- "local variable '{}' referenced before assignment" ,
2992- self . code. varnames[ idx2]
2993- )
2994- . into ( ) ,
2995- )
2962+ vm. new_unbound_local_error ( format ! (
2963+ "local variable '{}' referenced before assignment" ,
2964+ self . code. varnames[ idx2]
2965+ ) )
29962966 } ) ?;
29972967 self . push_value ( x1) ;
29982968 self . push_value ( x2) ;
0 commit comments