@@ -2637,6 +2637,32 @@ def test_format_simple(self):
26372637 ]
26382638 self .check (insts , expected )
26392639
2640+ def test_set_function_attribute (self ):
2641+ # SET_FUNCTION_ATTRIBUTE leaves the function on the stack
2642+ insts = [
2643+ ("LOAD_CONST" , 0 , 1 ),
2644+ ("LOAD_FAST" , 0 , 2 ),
2645+ ("SET_FUNCTION_ATTRIBUTE" , 2 , 3 ),
2646+ ("STORE_FAST" , 1 , 4 ),
2647+ ("LOAD_CONST" , 0 , 5 ),
2648+ ("RETURN_VALUE" , None , 6 )
2649+ ]
2650+ self .cfg_optimization_test (insts , insts , consts = [None ])
2651+
2652+ insts = [
2653+ ("LOAD_CONST" , 0 , 1 ),
2654+ ("LOAD_FAST" , 0 , 2 ),
2655+ ("SET_FUNCTION_ATTRIBUTE" , 2 , 3 ),
2656+ ("RETURN_VALUE" , None , 4 )
2657+ ]
2658+ expected = [
2659+ ("LOAD_CONST" , 0 , 1 ),
2660+ ("LOAD_FAST_BORROW" , 0 , 2 ),
2661+ ("SET_FUNCTION_ATTRIBUTE" , 2 , 3 ),
2662+ ("RETURN_VALUE" , None , 4 )
2663+ ]
2664+ self .cfg_optimization_test (insts , expected , consts = [None ])
2665+
26402666 def test_del_in_finally (self ):
26412667 # This loads `obj` onto the stack, executes `del obj`, then returns the
26422668 # `obj` from the stack. See gh-133371 for more details.
0 commit comments