Skip to content

Commit

Permalink
fix formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthieuDartiailh committed Jan 14, 2025
1 parent 9756ed0 commit a05a199
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/bytecode/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __iter__(self) -> Iterator[Union[Instr, SetLineno, TryBegin, TryEnd]]:
isinstance(self[i], Instr) for i in range(index, len(self))
):
raise ValueError(
"Only the last instruction of a basic " "block can be a jump"
"Only the last instruction of a basic block can be a jump"
)

if not isinstance(instr.arg, BasicBlock):
Expand Down
13 changes: 4 additions & 9 deletions src/bytecode/instr.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,12 @@ class FreeVar(_Variable):
def _check_arg_int(arg: Any, name: str) -> TypeGuard[int]:
if not isinstance(arg, int):
raise TypeError(
"operation %s argument must be an int, "
"got %s" % (name, type(arg).__name__)
"operation %s argument must be an int, got %s" % (name, type(arg).__name__)
)

if not (0 <= arg <= 2147483647):
raise ValueError(
"operation %s argument must be in " "the range 0..2,147,483,647" % name
"operation %s argument must be in the range 0..2,147,483,647" % name
)

return True
Expand Down Expand Up @@ -900,13 +899,9 @@ def _check_arg(self, name: str, opcode: int, arg: InstrArg) -> None:

elif opcode in _opcode.hasconst:
if isinstance(arg, Label):
raise ValueError(
"label argument cannot be used " "in %s operation" % name
)
raise ValueError("label argument cannot be used in %s operation" % name)
if isinstance(arg, _bytecode.BasicBlock):
raise ValueError(
"block argument cannot be used " "in %s operation" % name
)
raise ValueError("block argument cannot be used in %s operation" % name)

elif opcode in _opcode.hascompare:
if not isinstance(arg, Compare):
Expand Down
12 changes: 3 additions & 9 deletions tests/test_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,18 +668,12 @@ def test_to_code(self):
)
elif PY311:
# jump is relative not absolute
expected = (
b"|\x05" b"r\x02" b"|\x00" b"}\x05" b"d\x01" b"}\x05" b"|\x05" b"S\x00"
)
expected = b"|\x05r\x02|\x00}\x05d\x01}\x05|\x05S\x00"
elif OFFSET_AS_INSTRUCTION:
# The argument of the jump is divided by 2
expected = (
b"|\x05" b"r\x04" b"|\x00" b"}\x05" b"d\x01" b"}\x05" b"|\x05" b"S\x00"
)
expected = b"|\x05r\x04|\x00}\x05d\x01}\x05|\x05S\x00"
else:
expected = (
b"|\x05" b"r\x08" b"|\x00" b"}\x05" b"d\x01" b"}\x05" b"|\x05" b"S\x00"
)
expected = b"|\x05r\x08|\x00}\x05d\x01}\x05|\x05S\x00"

code = bytecode.to_code()
self.assertEqual(code.co_consts, (None, 3))
Expand Down

0 comments on commit a05a199

Please sign in to comment.