Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/bytecode/concrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,20 @@ def from_code(
pos_iter: Iterator[
Tuple[Optional[int], Optional[int], Optional[int], Optional[int]]
] = iter(code.co_positions())
_last_pos: Optional[
Tuple[Optional[int], Optional[int], Optional[int], Optional[int]]
] = None
_last_loc: Optional[InstrLocation] = None
for offset in range(0, len(bc), 2):
op = bc[offset]
arg = bc[offset + 1] if opcode_has_argument(op) else UNSET
pos = next(pos_iter, None)
loc: Optional[InstrLocation] = (
InstrLocation._from_tuple(*pos) if pos is not None else None
)
if pos == _last_pos:
loc: Optional[InstrLocation] = _last_loc
else:
loc = InstrLocation._from_tuple(*pos) if pos is not None else None
_last_pos = pos
_last_loc = loc
instructions.append(ConcreteInstr._from_opcode(opname[op], op, arg, loc))

bytecode = ConcreteBytecode()
Expand Down