@@ -124,8 +124,7 @@ def dis(x=None, *, file=None, depth=None, show_caches=False, adaptive=False,
124
124
formatter = Formatter (file = file ,
125
125
offset_width = len (str (max (len (x ) - 2 , 9999 ))) if show_offsets else 0 ,
126
126
label_width = label_width ,
127
- show_caches = show_caches ,
128
- show_positions = False )
127
+ show_caches = show_caches )
129
128
arg_resolver = ArgResolver (labels_map = labels_map )
130
129
_disassemble_bytes (x , arg_resolver = arg_resolver , formatter = formatter )
131
130
elif isinstance (x , str ): # Source code
@@ -427,26 +426,23 @@ def __str__(self):
427
426
428
427
class Formatter :
429
428
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 ):
432
431
"""Create a Formatter
433
432
434
433
*file* where to write the output
435
434
*lineno_width* sets the width of the line number field (0 omits it)
436
435
*offset_width* sets the width of the instruction offset field
436
+ *positions_width* sets the width of the instruction positions field (0 omits it)
437
437
*label_width* sets the width of the label field
438
438
*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.
443
439
"""
444
440
self .file = file
445
441
self .lineno_width = lineno_width
446
442
self .offset_width = offset_width
443
+ self .positions_width = positions_width
447
444
self .label_width = label_width
448
445
self .show_caches = show_caches
449
- self .show_positions = show_positions
450
446
451
447
def print_instruction (self , instr , mark_as_current = False ):
452
448
self .print_instruction_line (instr , mark_as_current )
@@ -778,14 +774,15 @@ def disassemble(co, lasti=-1, *, file=None, show_caches=False, adaptive=False,
778
774
"""Disassemble a code object."""
779
775
linestarts = dict (findlinestarts (co ))
780
776
exception_entries = _parse_exception_table (co )
777
+ positions_width = _get_positions_width (co ) if show_positions else 0
781
778
labels_map = _make_labels_map (co .co_code , exception_entries = exception_entries )
782
779
label_width = 4 + len (str (len (labels_map )))
783
780
formatter = Formatter (file = file ,
784
781
lineno_width = _get_lineno_width (linestarts ),
785
782
offset_width = len (str (max (len (co .co_code ) - 2 , 9999 ))) if show_offsets else 0 ,
783
+ positions_width = positions_width ,
786
784
label_width = label_width ,
787
- show_caches = show_caches ,
788
- show_positions = show_positions )
785
+ show_caches = show_caches )
789
786
arg_resolver = ArgResolver (co_consts = co .co_consts ,
790
787
names = co .co_names ,
791
788
varname_from_oparg = co ._varname_from_oparg ,
@@ -838,6 +835,8 @@ def _get_lineno_width(linestarts):
838
835
lineno_width = len (_NO_LINENO )
839
836
return lineno_width
840
837
838
+ def _get_positions_width (code ):
839
+ return 0
841
840
842
841
def _disassemble_bytes (code , lasti = - 1 , linestarts = None ,
843
842
* , line_offset = 0 , exception_entries = (),
@@ -1043,17 +1042,17 @@ def dis(self):
1043
1042
with io .StringIO () as output :
1044
1043
code = _get_code_array (co , self .adaptive )
1045
1044
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
1047
1046
1048
1047
labels_map = _make_labels_map (co .co_code , self .exception_entries )
1049
1048
label_width = 4 + len (str (len (labels_map )))
1050
1049
formatter = Formatter (file = output ,
1051
1050
lineno_width = _get_lineno_width (self ._linestarts ),
1052
1051
offset_width = offset_width ,
1052
+ positions_width = positions_width ,
1053
1053
label_width = label_width ,
1054
1054
line_offset = self ._line_offset ,
1055
- show_caches = self .show_caches ,
1056
- show_positions = show_positions )
1055
+ show_caches = self .show_caches )
1057
1056
1058
1057
arg_resolver = ArgResolver (co_consts = co .co_consts ,
1059
1058
names = co .co_names ,
0 commit comments