|
7 | 7 | import unittest |
8 | 8 |
|
9 | 9 | from bytecode import Bytecode, ConcreteInstr, FreeVar, Instr, Label, SetLineno |
10 | | -from bytecode.instr import BinaryOp, InstrLocation |
| 10 | +from bytecode.instr import BinaryOp, FormatValue, InstrLocation |
11 | 11 | from bytecode.utils import PY310, PY311, PY312, PY313, PY314 |
12 | 12 |
|
13 | 13 | from . import TestCase, get_code |
@@ -356,6 +356,41 @@ def func(): |
356 | 356 | ), |
357 | 357 | ) |
358 | 358 |
|
| 359 | + def test_from_code_str_format(self): |
| 360 | + code = get_code( |
| 361 | + """ |
| 362 | + def func(a): |
| 363 | + return f"{a!r}" |
| 364 | + """, |
| 365 | + function=True, |
| 366 | + ) |
| 367 | + code = Bytecode.from_code(code) |
| 368 | + self.assertInstructionListEqual( |
| 369 | + code, |
| 370 | + ( |
| 371 | + [ |
| 372 | + Instr("RESUME", 0, lineno=1), |
| 373 | + ] |
| 374 | + if PY311 |
| 375 | + else [] |
| 376 | + ) |
| 377 | + + ( |
| 378 | + [ |
| 379 | + Instr("LOAD_FAST_BORROW", "a", lineno=2) |
| 380 | + if PY314 |
| 381 | + else Instr("LOAD_FAST", "a", lineno=2), |
| 382 | + Instr("CONVERT_VALUE", FormatValue.REPR, lineno=2), |
| 383 | + Instr("RETURN_VALUE", lineno=2), |
| 384 | + ] |
| 385 | + if PY313 |
| 386 | + else [ |
| 387 | + Instr("LOAD_FAST", "a", lineno=2), |
| 388 | + Instr("FORMAT_VALUE", 2, lineno=2), |
| 389 | + Instr("RETURN_VALUE", lineno=2), |
| 390 | + ] |
| 391 | + ), |
| 392 | + ) |
| 393 | + |
359 | 394 | def test_setlineno(self): |
360 | 395 | # x = 7 |
361 | 396 | # y = 8 |
|
0 commit comments