2121 SetLineno ,
2222)
2323from bytecode .concrete import ExceptionTableEntry
24+ from bytecode .instr import CommonConstant
2425from bytecode .utils import PY312 , PY313 , PY314 , PY315
2526
2627from . import TestCase , get_code
@@ -244,7 +245,7 @@ def test_eq(self):
244245 def test_attr (self ):
245246 code_obj = get_code ("x = 5" )
246247 code = ConcreteBytecode .from_code (code_obj )
247- self .assertEqual (code .consts , [5 , None ])
248+ self .assertEqual (code .consts , [5 ] if PY315 else [ 5 , None ])
248249 self .assertEqual (code .names , ["x" ])
249250 self .assertEqual (code .varnames , [])
250251 self .assertEqual (code .freevars , [])
@@ -256,7 +257,7 @@ def test_attr(self):
256257 ConcreteInstr ("CACHE" , 0 , lineno = 0 ),
257258 ConcreteInstr ("LOAD_SMALL_INT" , 5 , lineno = 1 ),
258259 ConcreteInstr ("STORE_NAME" , 0 , lineno = 1 ),
259- ConcreteInstr ("LOAD_CONST " , 1 , lineno = 1 ),
260+ ConcreteInstr ("LOAD_COMMON_CONSTANT " , 7 , lineno = 1 ),
260261 ConcreteInstr ("RETURN_VALUE" , lineno = 1 ),
261262 ]
262263 if PY315
@@ -333,7 +334,9 @@ def f():
333334 ]
334335 + (
335336 [
336- ConcreteInstr ("LOAD_CONST" , 1 ),
337+ ConcreteInstr ("LOAD_COMMON_CONSTANT" , CommonConstant .CONSTANT_NONE )
338+ if PY315
339+ else ConcreteInstr ("LOAD_CONST" , 1 ),
337340 ConcreteInstr ("RETURN_VALUE" ),
338341 ]
339342 if PY314
@@ -457,7 +460,9 @@ def test_extended_lnotab2(self):
457460 ]
458461 + (
459462 [
460- ConcreteInstr ("LOAD_CONST" , 1 ),
463+ ConcreteInstr ("LOAD_COMMON_CONSTANT" , CommonConstant .CONSTANT_NONE )
464+ if PY315
465+ else ConcreteInstr ("LOAD_CONST" , 1 ),
461466 ConcreteInstr ("RETURN_VALUE" ),
462467 ]
463468 if PY314
@@ -764,17 +769,18 @@ def foo(x: int, y: int):
764769 ConcreteInstr ("MAKE_FUNCTION" , lineno = 1 ),
765770 ConcreteInstr ("SET_FUNCTION_ATTRIBUTE" , 16 , lineno = 1 ),
766771 ConcreteInstr ("STORE_NAME" , 0 , lineno = 1 ),
767- ConcreteInstr ("LOAD_CONST " , 2 , lineno = 1 ),
772+ ConcreteInstr ("LOAD_COMMON_CONSTANT " , 7 , lineno = 1 ),
768773 ConcreteInstr ("RETURN_VALUE" , lineno = 1 ),
769774 ]
775+ expected_consts = [ann_code , func_code ]
770776 self .assertSequenceEqual (concrete .names , ["foo" ])
771- self .assertSequenceEqual (concrete .consts , [ ann_code , func_code , None ] )
777+ self .assertSequenceEqual (concrete .consts , expected_consts )
772778 self .assertInstructionListEqual (list (concrete ), expected_py315 )
773779 concrete = ConcreteBytecode .from_code (code_obj , extended_arg = True )
774780 ann_code = concrete .consts [0 ]
775781 func_code = concrete .consts [1 ]
776782 self .assertEqual (concrete .names , ["foo" ])
777- self .assertEqual (concrete .consts , [ ann_code , func_code , None ] )
783+ self .assertEqual (concrete .consts , expected_consts )
778784 self .assertInstructionListEqual (list (concrete ), expected_py315 )
779785 return
780786 if PY314 :
0 commit comments