Skip to content

Commit 3157e24

Browse files
committed
add dummy _get_positions_width function
1 parent 0fdc1dd commit 3157e24

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

Lib/dis.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ def dis(x=None, *, file=None, depth=None, show_caches=False, adaptive=False,
124124
formatter = Formatter(file=file,
125125
offset_width=len(str(max(len(x) - 2, 9999))) if show_offsets else 0,
126126
label_width=label_width,
127-
show_caches=show_caches,
128-
show_positions=False)
127+
show_caches=show_caches)
129128
arg_resolver = ArgResolver(labels_map=labels_map)
130129
_disassemble_bytes(x, arg_resolver=arg_resolver, formatter=formatter)
131130
elif isinstance(x, str): # Source code
@@ -427,26 +426,23 @@ def __str__(self):
427426

428427
class Formatter:
429428

430-
def __init__(self, file=None, lineno_width=0, offset_width=0, label_width=0,
431-
line_offset=0, show_caches=False, show_positions=False):
429+
def __init__(self, file=None, lineno_width=0, offset_width=0, positions_width=0, label_width=0,
430+
line_offset=0, show_caches=False):
432431
"""Create a Formatter
433432
434433
*file* where to write the output
435434
*lineno_width* sets the width of the line number field (0 omits it)
436435
*offset_width* sets the width of the instruction offset field
436+
*positions_width* sets the width of the instruction positions field (0 omits it)
437437
*label_width* sets the width of the label field
438438
*show_caches* is a boolean indicating whether to display cache lines
439-
*show_positions* is a boolean indicate whether to display positions
440-
441-
If *show_positions* is true, *lineno_width* should take into account
442-
the width that positions would take.
443439
"""
444440
self.file = file
445441
self.lineno_width = lineno_width
446442
self.offset_width = offset_width
443+
self.positions_width = positions_width
447444
self.label_width = label_width
448445
self.show_caches = show_caches
449-
self.show_positions = show_positions
450446

451447
def print_instruction(self, instr, mark_as_current=False):
452448
self.print_instruction_line(instr, mark_as_current)
@@ -778,14 +774,15 @@ def disassemble(co, lasti=-1, *, file=None, show_caches=False, adaptive=False,
778774
"""Disassemble a code object."""
779775
linestarts = dict(findlinestarts(co))
780776
exception_entries = _parse_exception_table(co)
777+
positions_width = _get_positions_width(co) if show_positions else 0
781778
labels_map = _make_labels_map(co.co_code, exception_entries=exception_entries)
782779
label_width = 4 + len(str(len(labels_map)))
783780
formatter = Formatter(file=file,
784781
lineno_width=_get_lineno_width(linestarts),
785782
offset_width=len(str(max(len(co.co_code) - 2, 9999))) if show_offsets else 0,
783+
positions_width=positions_width,
786784
label_width=label_width,
787-
show_caches=show_caches,
788-
show_positions=show_positions)
785+
show_caches=show_caches)
789786
arg_resolver = ArgResolver(co_consts=co.co_consts,
790787
names=co.co_names,
791788
varname_from_oparg=co._varname_from_oparg,
@@ -838,6 +835,8 @@ def _get_lineno_width(linestarts):
838835
lineno_width = len(_NO_LINENO)
839836
return lineno_width
840837

838+
def _get_positions_width(code):
839+
return 0
841840

842841
def _disassemble_bytes(code, lasti=-1, linestarts=None,
843842
*, line_offset=0, exception_entries=(),
@@ -1043,17 +1042,17 @@ def dis(self):
10431042
with io.StringIO() as output:
10441043
code = _get_code_array(co, self.adaptive)
10451044
offset_width = len(str(max(len(code) - 2, 9999))) if self.show_offsets else 0
1046-
1045+
positions_width = _get_positions_width(co) if self.show_positions else 0
10471046

10481047
labels_map = _make_labels_map(co.co_code, self.exception_entries)
10491048
label_width = 4 + len(str(len(labels_map)))
10501049
formatter = Formatter(file=output,
10511050
lineno_width=_get_lineno_width(self._linestarts),
10521051
offset_width=offset_width,
1052+
positions_width=positions_width,
10531053
label_width=label_width,
10541054
line_offset=self._line_offset,
1055-
show_caches=self.show_caches,
1056-
show_positions=show_positions)
1055+
show_caches=self.show_caches)
10571056

10581057
arg_resolver = ArgResolver(co_consts=co.co_consts,
10591058
names=co.co_names,

0 commit comments

Comments
 (0)