Skip to content

Commit 8466406

Browse files
fix typing and minor test issues
1 parent d2e9edd commit 8466406

3 files changed

Lines changed: 46 additions & 4 deletions

File tree

src/bytecode/concrete.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,9 +1066,7 @@ def to_bytecode(
10661066
if opcode in BITFLAG_OPCODES:
10671067
arg = (
10681068
bool(c_arg & 1),
1069-
FormatValue(c_arg >> 1)
1070-
if opcode in FORMAT_VALUE_OPS
1071-
else self.names[c_arg >> 1],
1069+
self.names[c_arg >> 1],
10721070
)
10731071
elif opcode in BITFLAG2_OPCODES:
10741072
arg = (bool(c_arg & 1), bool(c_arg & 2), self.names[c_arg >> 2])
@@ -1101,6 +1099,14 @@ def to_bytecode(
11011099
arg = CommonConstants(c_arg)
11021100
elif opcode in SPECIAL_OPS:
11031101
arg = SpecialMethod(c_arg)
1102+
elif opcode in FORMAT_VALUE_OPS:
1103+
if opcode in BITFLAG_OPCODES:
1104+
arg = (
1105+
bool(c_arg & 1),
1106+
FormatValue(c_arg >> 1),
1107+
)
1108+
else:
1109+
arg = FormatValue(c_arg)
11041110
else:
11051111
arg = c_arg
11061112

src/bytecode/instr.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,8 +868,15 @@ def _cmp_key(self) -> Tuple[Optional[InstrLocation], str, Any]:
868868
FreeVar,
869869
"_bytecode.BasicBlock",
870870
Compare,
871+
FormatValue,
872+
BinaryOp,
873+
Intrinsic1Op,
874+
Intrinsic2Op,
875+
CommonConstants,
876+
SpecialMethod,
871877
Tuple[bool, str],
872878
Tuple[bool, bool, str],
879+
Tuple[bool, FormatValue],
873880
Tuple[Union[str, CellVar, FreeVar], Union[str, CellVar, FreeVar]],
874881
]
875882

tests/test_misc.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ def func(test):
388388
self.check_dump_bytecode(code, expected.lstrip())
389389

390390
# with line numbers
391-
if PY312:
391+
if PY314:
392392
expected = textwrap.dedent(
393393
f"""
394394
block1:
@@ -420,6 +420,35 @@ def func(test):
420420
L. 6 0: LOAD_SMALL_INT 3
421421
1: RETURN_VALUE
422422
423+
"""
424+
)
425+
elif PY312:
426+
expected = textwrap.dedent(
427+
f"""
428+
block1:
429+
L. 1 0: RESUME 0
430+
L. 2 1: LOAD_FAST 'test'
431+
2: LOAD_CONST 1
432+
3: COMPARE_OP {enum_repr}
433+
4: POP_JUMP_IF_FALSE <block3>
434+
-> block2
435+
436+
block2:
437+
L. 3 1: RETURN_CONST 1
438+
439+
block3:
440+
L. 4 0: LOAD_FAST 'test'
441+
1: LOAD_CONST 2
442+
2: COMPARE_OP {enum_repr}
443+
3: POP_JUMP_IF_FALSE <block5>
444+
-> block4
445+
446+
block4:
447+
L. 5 1: RETURN_CONST 2
448+
449+
block5:
450+
L. 6 0: RETURN_CONST 3
451+
423452
"""
424453
)
425454
elif PY311:

0 commit comments

Comments
 (0)