|
21 | 21 | SetLineno, |
22 | 22 | ) |
23 | 23 | from bytecode.concrete import ExceptionTableEntry |
24 | | -from bytecode.utils import PY312, PY313, PY314 |
| 24 | +from bytecode.utils import PY312, PY313, PY314, PY315 |
25 | 25 |
|
26 | 26 | from . import TestCase, get_code |
27 | 27 |
|
@@ -250,24 +250,37 @@ def test_attr(self): |
250 | 250 | self.assertEqual(code.freevars, []) |
251 | 251 | self.assertInstructionListEqual( |
252 | 252 | list(code), |
253 | | - ([ConcreteInstr("RESUME", 0, lineno=0)]) |
254 | | - + [ |
255 | | - ConcreteInstr("LOAD_CONST", 0, lineno=1), |
256 | | - ConcreteInstr("STORE_NAME", 0, lineno=1), |
257 | | - ] |
258 | | - + ( |
| 253 | + ( |
259 | 254 | [ |
260 | | - ConcreteInstr("LOAD_SMALL_INT", 1, lineno=1), |
| 255 | + ConcreteInstr("RESUME", 0, lineno=0), |
| 256 | + ConcreteInstr("CACHE", 0, lineno=0), |
| 257 | + ConcreteInstr("LOAD_SMALL_INT", 5, lineno=1), |
| 258 | + ConcreteInstr("STORE_NAME", 0, lineno=1), |
| 259 | + ConcreteInstr("LOAD_CONST", 1, lineno=1), |
261 | 260 | ConcreteInstr("RETURN_VALUE", lineno=1), |
262 | 261 | ] |
263 | | - if PY314 |
| 262 | + if PY315 |
264 | 263 | else ( |
265 | | - [ConcreteInstr("RETURN_CONST", 1, lineno=1)] |
266 | | - if PY312 |
267 | | - else [ |
268 | | - ConcreteInstr("LOAD_CONST", 1, lineno=1), |
269 | | - ConcreteInstr("RETURN_VALUE", lineno=1), |
| 264 | + [ConcreteInstr("RESUME", 0, lineno=0)] |
| 265 | + + [ |
| 266 | + ConcreteInstr("LOAD_CONST", 0, lineno=1), |
| 267 | + ConcreteInstr("STORE_NAME", 0, lineno=1), |
270 | 268 | ] |
| 269 | + + ( |
| 270 | + [ |
| 271 | + ConcreteInstr("LOAD_SMALL_INT", 1, lineno=1), |
| 272 | + ConcreteInstr("RETURN_VALUE", lineno=1), |
| 273 | + ] |
| 274 | + if PY314 |
| 275 | + else ( |
| 276 | + [ConcreteInstr("RETURN_CONST", 1, lineno=1)] |
| 277 | + if PY312 |
| 278 | + else [ |
| 279 | + ConcreteInstr("LOAD_CONST", 1, lineno=1), |
| 280 | + ConcreteInstr("RETURN_VALUE", lineno=1), |
| 281 | + ] |
| 282 | + ) |
| 283 | + ) |
271 | 284 | ) |
272 | 285 | ), |
273 | 286 | ) |
@@ -739,6 +752,31 @@ def foo(x: int, y: int): |
739 | 752 |
|
740 | 753 | # without EXTENDED_ARG |
741 | 754 | concrete = ConcreteBytecode.from_code(code_obj) |
| 755 | + if PY315: |
| 756 | + ann_code = concrete.consts[0] |
| 757 | + func_code = concrete.consts[1] |
| 758 | + expected_py315 = [ |
| 759 | + ConcreteInstr("RESUME", 0, lineno=0), |
| 760 | + ConcreteInstr("CACHE", 0, lineno=0), |
| 761 | + ConcreteInstr("LOAD_CONST", 0, lineno=1), |
| 762 | + ConcreteInstr("MAKE_FUNCTION", lineno=1), |
| 763 | + ConcreteInstr("LOAD_CONST", 1, lineno=1), |
| 764 | + ConcreteInstr("MAKE_FUNCTION", lineno=1), |
| 765 | + ConcreteInstr("SET_FUNCTION_ATTRIBUTE", 16, lineno=1), |
| 766 | + ConcreteInstr("STORE_NAME", 0, lineno=1), |
| 767 | + ConcreteInstr("LOAD_CONST", 2, lineno=1), |
| 768 | + ConcreteInstr("RETURN_VALUE", lineno=1), |
| 769 | + ] |
| 770 | + self.assertSequenceEqual(concrete.names, ["foo"]) |
| 771 | + self.assertSequenceEqual(concrete.consts, [ann_code, func_code, None]) |
| 772 | + self.assertInstructionListEqual(list(concrete), expected_py315) |
| 773 | + concrete = ConcreteBytecode.from_code(code_obj, extended_arg=True) |
| 774 | + ann_code = concrete.consts[0] |
| 775 | + func_code = concrete.consts[1] |
| 776 | + self.assertEqual(concrete.names, ["foo"]) |
| 777 | + self.assertEqual(concrete.consts, [ann_code, func_code, None]) |
| 778 | + self.assertInstructionListEqual(list(concrete), expected_py315) |
| 779 | + return |
742 | 780 | if PY314: |
743 | 781 | ann_code = concrete.consts[0] |
744 | 782 | func_code = concrete.consts[1] |
|
0 commit comments