Skip to content

Commit 483c683

Browse files
committed
assume co_positions always available
1 parent daa1193 commit 483c683

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

src/bytecode/concrete.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -343,19 +343,15 @@ def from_code(
343343
# available from Python 3.11+. CACHE entries are already inline in
344344
# co_code on all supported versions, so iterating co_code directly
345345
# handles all versions without dis overhead.
346-
pos_iter: Optional[
347-
Iterator[Tuple[Optional[int], Optional[int], Optional[int], Optional[int]]]
348-
] = iter(code.co_positions()) if hasattr(code, "co_positions") else None
346+
pos_iter: Iterator[
347+
Tuple[Optional[int], Optional[int], Optional[int], Optional[int]]
348+
] = iter(code.co_positions())
349349
for offset in range(0, len(bc), 2):
350-
op = bc[offset]
351-
arg = bc[offset + 1] if opcode_has_argument(op) else UNSET
352-
if pos_iter is not None:
353-
pos = next(pos_iter, None)
354-
loc: Optional[InstrLocation] = (
355-
InstrLocation(*pos) if pos is not None else None
356-
)
357-
else:
358-
loc = None
350+
arg = bc[offset + 1] if opcode_has_argument(op := bc[offset]) else UNSET
351+
pos = next(pos_iter, None)
352+
loc: Optional[InstrLocation] = (
353+
InstrLocation(*pos) if pos is not None else None
354+
)
359355
instructions.append(ConcreteInstr(opname[op], arg, location=loc))
360356

361357
bytecode = ConcreteBytecode()

0 commit comments

Comments
 (0)