Skip to content

Commit d98ee89

Browse files
Fix async generator issue and prefer opcode comparison to name comparison everywhere (#179)
* ci: fix url for release (not sure it really matters) * tests: add test for async generator * prefer opcode comparison to name comparison * update changelog
1 parent 5229b3e commit d98ee89

6 files changed

Lines changed: 209 additions & 150 deletions

File tree

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
runs-on: ubuntu-latest
7575
environment:
7676
name: pypi
77-
url: https://pypi.org/p/kiwisolver
77+
url: https://pypi.org/p/bytecode
7878
permissions:
7979
id-token: write
8080
steps:

doc/changelog.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
ChangeLog
22
=========
33

4+
unreleased: Version 0.18.0
5+
--------------------------
6+
7+
- drop support for Python 3.9 and 3.10 PR #180
8+
9+
Bugfixes:
10+
11+
- Fix handling of END_ASYNC_FOR which is a backward jump PR #179
12+
413
03-09-2025: Version 0.17.0
514
--------------------------
615

src/bytecode/concrete.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@
2929
BINARY_OPS,
3030
BITFLAG2_OPCODES,
3131
BITFLAG_OPCODES,
32+
CACHE_OPCODE,
3233
COMMON_CONSTANT_OPS,
3334
DUAL_ARG_OPCODES,
3435
DUAL_ARG_OPCODES_SINGLE_OPS,
36+
EXTENDEDARG_OPCODE,
3537
FORMAT_VALUE_OPS,
3638
INTRINSIC,
3739
INTRINSIC_1OP,
3840
INTRINSIC_2OP,
41+
NOP_OPCODE,
3942
PLACEHOLDER_LABEL,
4043
SPECIAL_OPS,
4144
UNSET,
@@ -614,7 +617,7 @@ def _remove_extended_args(
614617
index += 1
615618
continue
616619

617-
if instr.name == "EXTENDED_ARG":
620+
if instr._opcode == EXTENDEDARG_OPCODE:
618621
nb_extended_args += 1
619622
if extended_arg is not None:
620623
extended_arg = (extended_arg << 8) + instr.arg
@@ -625,11 +628,15 @@ def _remove_extended_args(
625628
continue
626629

627630
if extended_arg is not None:
628-
arg = UNSET if instr.name == "NOP" else (extended_arg << 8) + instr.arg
631+
arg = (
632+
UNSET
633+
if instr._opcode == NOP_OPCODE
634+
else (extended_arg << 8) + instr.arg
635+
)
629636
extended_arg = None
630637

631638
instr = ConcreteInstr(
632-
instr.name,
639+
instr._name,
633640
arg,
634641
location=instr.location,
635642
extended_args=nb_extended_args,
@@ -854,7 +861,7 @@ def to_bytecode(
854861
# on Python 3.11+ remove CACHE opcodes if we are requested to do so.
855862
# We are careful to first advance the offset and check that the CACHE
856863
# is not a jump target. It should never be the case but we double check.
857-
if prune_caches and c_instr._name == "CACHE":
864+
if prune_caches and c_instr._opcode == CACHE_OPCODE:
858865
if jump_target is not None:
859866
msg = "cache instruction cannot have jump target"
860867
raise ValueError(msg)
@@ -1043,7 +1050,7 @@ def concrete_instructions(self) -> None:
10431050
for instr in itertools.chain(self.bytecode, [None]):
10441051
# Enforce proper use of CACHE opcode on Python 3.11+ by checking we get the
10451052
# number we expect or directly generate the needed ones.
1046-
if isinstance(instr, Instr) and instr._name == "CACHE":
1053+
if isinstance(instr, Instr) and instr._opcode == CACHE_OPCODE:
10471054
if not self.required_caches:
10481055
raise RuntimeError("Found a CACHE opcode when none was expected.")
10491056
self.seen_manual_cache = True

src/bytecode/flags.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# alias to keep the 'bytecode' variable free
66
import bytecode as _bytecode
77

8-
from .instr import DUAL_ARG_OPCODES, CellVar, FreeVar
8+
from .instr import DUAL_ARG_OPCODES, RESUME_OPCODE, CellVar, FreeVar
99
from .utils import PY312, PY313, PY314
1010

1111

@@ -130,7 +130,7 @@ def infer_flags(
130130
),
131131
):
132132
pass
133-
assert ni.name == "RESUME"
133+
assert ni._opcode == RESUME_OPCODE
134134
if (ni.arg & 3) != 3:
135135
known_generator = True
136136
else:

0 commit comments

Comments
 (0)