|
21 | 21 | SetLineno, |
22 | 22 | ) |
23 | 23 | from bytecode.concrete import OFFSET_AS_INSTRUCTION, ExceptionTableEntry |
24 | | -from bytecode.utils import PY310, PY311, PY312, PY313, PY314 |
| 24 | +from bytecode.utils import PY310, PY311, PY312, PY313, PY314, PY315 |
25 | 25 |
|
26 | 26 | from . import TestCase, get_code |
27 | 27 |
|
@@ -256,24 +256,37 @@ def test_attr(self): |
256 | 256 | self.assertEqual(code.freevars, []) |
257 | 257 | self.assertInstructionListEqual( |
258 | 258 | list(code), |
259 | | - ([ConcreteInstr("RESUME", 0, lineno=0)] if PY311 else []) |
260 | | - + [ |
261 | | - ConcreteInstr("LOAD_CONST", 0, lineno=1), |
262 | | - ConcreteInstr("STORE_NAME", 0, lineno=1), |
263 | | - ] |
264 | | - + ( |
| 259 | + ( |
265 | 260 | [ |
266 | | - ConcreteInstr("LOAD_SMALL_INT", 1, lineno=1), |
| 261 | + ConcreteInstr("RESUME", 0, lineno=0), |
| 262 | + ConcreteInstr("CACHE", 0, lineno=0), |
| 263 | + ConcreteInstr("LOAD_SMALL_INT", 5, lineno=1), |
| 264 | + ConcreteInstr("STORE_NAME", 0, lineno=1), |
| 265 | + ConcreteInstr("LOAD_CONST", 1, lineno=1), |
267 | 266 | ConcreteInstr("RETURN_VALUE", lineno=1), |
268 | 267 | ] |
269 | | - if PY314 |
| 268 | + if PY315 |
270 | 269 | else ( |
271 | | - [ConcreteInstr("RETURN_CONST", 1, lineno=1)] |
272 | | - if PY312 |
273 | | - else [ |
274 | | - ConcreteInstr("LOAD_CONST", 1, lineno=1), |
275 | | - ConcreteInstr("RETURN_VALUE", lineno=1), |
| 270 | + ([ConcreteInstr("RESUME", 0, lineno=0)] if PY311 else []) |
| 271 | + + [ |
| 272 | + ConcreteInstr("LOAD_CONST", 0, lineno=1), |
| 273 | + ConcreteInstr("STORE_NAME", 0, lineno=1), |
276 | 274 | ] |
| 275 | + + ( |
| 276 | + [ |
| 277 | + ConcreteInstr("LOAD_SMALL_INT", 1, lineno=1), |
| 278 | + ConcreteInstr("RETURN_VALUE", lineno=1), |
| 279 | + ] |
| 280 | + if PY314 |
| 281 | + else ( |
| 282 | + [ConcreteInstr("RETURN_CONST", 1, lineno=1)] |
| 283 | + if PY312 |
| 284 | + else [ |
| 285 | + ConcreteInstr("LOAD_CONST", 1, lineno=1), |
| 286 | + ConcreteInstr("RETURN_VALUE", lineno=1), |
| 287 | + ] |
| 288 | + ) |
| 289 | + ) |
277 | 290 | ) |
278 | 291 | ), |
279 | 292 | ) |
@@ -824,6 +837,31 @@ def foo(x: int, y: int): |
824 | 837 |
|
825 | 838 | # without EXTENDED_ARG |
826 | 839 | concrete = ConcreteBytecode.from_code(code_obj) |
| 840 | + if PY315: |
| 841 | + ann_code = concrete.consts[0] |
| 842 | + func_code = concrete.consts[1] |
| 843 | + expected_py315 = [ |
| 844 | + ConcreteInstr("RESUME", 0, lineno=0), |
| 845 | + ConcreteInstr("CACHE", 0, lineno=0), |
| 846 | + ConcreteInstr("LOAD_CONST", 0, lineno=1), |
| 847 | + ConcreteInstr("MAKE_FUNCTION", lineno=1), |
| 848 | + ConcreteInstr("LOAD_CONST", 1, lineno=1), |
| 849 | + ConcreteInstr("MAKE_FUNCTION", lineno=1), |
| 850 | + ConcreteInstr("SET_FUNCTION_ATTRIBUTE", 16, lineno=1), |
| 851 | + ConcreteInstr("STORE_NAME", 0, lineno=1), |
| 852 | + ConcreteInstr("LOAD_CONST", 2, lineno=1), |
| 853 | + ConcreteInstr("RETURN_VALUE", lineno=1), |
| 854 | + ] |
| 855 | + self.assertSequenceEqual(concrete.names, ["foo"]) |
| 856 | + self.assertSequenceEqual(concrete.consts, [ann_code, func_code, None]) |
| 857 | + self.assertInstructionListEqual(list(concrete), expected_py315) |
| 858 | + concrete = ConcreteBytecode.from_code(code_obj, extended_arg=True) |
| 859 | + ann_code = concrete.consts[0] |
| 860 | + func_code = concrete.consts[1] |
| 861 | + self.assertEqual(concrete.names, ["foo"]) |
| 862 | + self.assertEqual(concrete.consts, [ann_code, func_code, None]) |
| 863 | + self.assertInstructionListEqual(list(concrete), expected_py315) |
| 864 | + return |
827 | 865 | if PY314: |
828 | 866 | ann_code = concrete.consts[0] |
829 | 867 | func_code = concrete.consts[1] |
|
0 commit comments