Skip to content

Commit 457c2a9

Browse files
author
rocky
committed
black bytecode.py
1 parent d3bc0f9 commit 457c2a9

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

xdis/bytecode.py

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def get_logical_instruction_at_offset(
234234
linestarts=None,
235235
line_offset=0,
236236
exception_entries=None,
237-
labels = None
237+
labels=None,
238238
):
239239
"""
240240
Return a single logical instruction for `bytecode` at offset `offset`.
@@ -306,11 +306,7 @@ def get_logical_instruction_at_offset(
306306
+ extended_arg
307307
)
308308
i += 2
309-
extended_arg = (
310-
arg * 0x10000
311-
if opname == "EXTENDED_ARG"
312-
else 0
313-
)
309+
extended_arg = arg * 0x10000 if opname == "EXTENDED_ARG" else 0
314310

315311
# Set argval to the dereferenced value of the argument when
316312
# available, and argrepr to the string representation of argval.
@@ -320,7 +316,9 @@ def get_logical_instruction_at_offset(
320316
argval = arg
321317

322318
# create a localsplusnames table that resolves duplicates.
323-
localsplusnames = (varnames or tuple()) + tuple(name for name in (cells or tuple()) if name not in varnames)
319+
localsplusnames = (varnames or tuple()) + tuple(
320+
name for name in (cells or tuple()) if name not in varnames
321+
)
324322

325323
if op in opc.CONST_OPS:
326324
argval, argrepr = _get_const_info(arg, constants)
@@ -333,9 +331,7 @@ def get_logical_instruction_at_offset(
333331
argval, argrepr = _get_name_info(arg >> 1, names)
334332
if arg & 1:
335333
argrepr = "NULL|self + " + argrepr
336-
elif (
337-
opc.version_tuple >= (3, 12) and opname == "LOAD_SUPER_ATTR"
338-
):
334+
elif opc.version_tuple >= (3, 12) and opname == "LOAD_SUPER_ATTR":
339335
argval, argrepr = _get_name_info(arg >> 2, names)
340336
if arg & 1:
341337
argrepr = "NULL|self + " + argrepr
@@ -347,7 +343,13 @@ def get_logical_instruction_at_offset(
347343

348344
# check cache instructions for python 3.13
349345
if opc.version_tuple >= (3, 13):
350-
if opc.opname[op] in ["POP_JUMP_IF_TRUE", "POP_JUMP_IF_FALSE", "POP_JUMP_IF_NONE", "POP_JUMP_IF_NOT_NONE", "JUMP_BACKWARD"]:
346+
if opc.opname[op] in [
347+
"POP_JUMP_IF_TRUE",
348+
"POP_JUMP_IF_FALSE",
349+
"POP_JUMP_IF_NONE",
350+
"POP_JUMP_IF_NOT_NONE",
351+
"JUMP_BACKWARD",
352+
]:
351353
argval += 2
352354

353355
# FOR_ITER has a cache instruction in 3.12
@@ -358,7 +360,11 @@ def get_logical_instruction_at_offset(
358360
argval = get_jump_val(arg, opc.python_version)
359361
argrepr = "to " + repr(argval)
360362
elif op in opc.LOCAL_OPS:
361-
if opc.version_tuple >= (3, 13) and opname in ("LOAD_FAST_LOAD_FAST", "STORE_FAST_LOAD_FAST", "STORE_FAST_STORE_FAST"):
363+
if opc.version_tuple >= (3, 13) and opname in (
364+
"LOAD_FAST_LOAD_FAST",
365+
"STORE_FAST_LOAD_FAST",
366+
"STORE_FAST_STORE_FAST",
367+
):
362368
arg1 = arg >> 4
363369
arg2 = arg & 15
364370
argval1, argrepr1 = _get_name_info(arg1, localsplusnames)
@@ -377,11 +383,11 @@ def get_logical_instruction_at_offset(
377383
elif op in opc.COMPARE_OPS:
378384
if opc.python_version >= (3, 13):
379385
# The fifth-lowest bit of the oparg now indicates a forced conversion to bool.
380-
argval = (opc.cmp_op[arg >> 5])
386+
argval = opc.cmp_op[arg >> 5]
381387
elif opc.python_version >= (3, 12):
382-
argval = (opc.cmp_op[arg >> 4])
388+
argval = opc.cmp_op[arg >> 4]
383389
else:
384-
argval = (opc.cmp_op[arg])
390+
argval = opc.cmp_op[arg]
385391
argrepr = argval
386392
elif op in opc.NARGS_OPS:
387393
opname = opname
@@ -473,17 +479,18 @@ def get_instructions_bytes(
473479
offset = 0
474480

475481
while offset < n:
476-
instructions = list(get_logical_instruction_at_offset(
477-
bytecode,
478-
offset,
479-
opc,
480-
varnames=varnames,
481-
names=names,
482-
constants=constants,
483-
cells=cells,
484-
linestarts=linestarts,
485-
line_offset=0,
486-
exception_entries=exception_entries,
482+
instructions = list(
483+
get_logical_instruction_at_offset(
484+
bytecode,
485+
offset,
486+
opc,
487+
varnames=varnames,
488+
names=names,
489+
constants=constants,
490+
cells=cells,
491+
linestarts=linestarts,
492+
line_offset=0,
493+
exception_entries=exception_entries,
487494
)
488495
)
489496

@@ -492,7 +499,6 @@ def get_instructions_bytes(
492499
offset = next_offset(instruction.opcode, opc, instruction.offset)
493500

494501

495-
496502
class Bytecode:
497503
"""Bytecode operations involving a Python code object.
498504

0 commit comments

Comments
 (0)