Skip to content

Commit de06a89

Browse files
revert: block bg
1 parent da2329b commit de06a89

2 files changed

Lines changed: 16 additions & 45 deletions

File tree

Lib/_colorize.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class ANSIColors:
4848
BACKGROUND_BLUE = "\x1b[44m"
4949
BACKGROUND_CYAN = "\x1b[46m"
5050
BACKGROUND_GREEN = "\x1b[42m"
51-
BACKGROUND_GREY = "\x1b[48;5;236m"
5251
BACKGROUND_MAGENTA = "\x1b[45m"
5352
BACKGROUND_RED = "\x1b[41m"
5453
BACKGROUND_WHITE = "\x1b[47m"
@@ -220,9 +219,6 @@ class Difflib(ThemeSection):
220219

221220
@dataclass(frozen=True, kw_only=True)
222221
class Dis(ThemeSection):
223-
alt_block_first_bg:str = ANSIColors.BACKGROUND_GREY
224-
alt_block_second_bg:str = ANSIColors.RESET # mb black bg ? but what about light mode ?
225-
226222
label_bg: str = ANSIColors.BACKGROUND_CYAN
227223
label_fg: str = ANSIColors.BLACK
228224

Lib/dis.py

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def _try_compile(source, name):
8484
return compile(source, name, 'exec')
8585

8686
def dis(x=None, *, file=None, depth=None, show_caches=False, adaptive=False,
87-
show_offsets=False, show_positions=False, show_jit=False,show_block_bg=False):
87+
show_offsets=False, show_positions=False, show_jit=False):
8888
"""Disassemble classes, methods, functions, and other compiled objects.
8989
9090
With no argument, disassemble the last traceback.
@@ -96,7 +96,7 @@ def dis(x=None, *, file=None, depth=None, show_caches=False, adaptive=False,
9696
if x is None:
9797
distb(file=file, show_caches=show_caches, adaptive=adaptive,
9898
show_offsets=show_offsets, show_positions=show_positions,
99-
show_jit=show_jit, show_block_bg=show_block_bg)
99+
show_jit=show_jit)
100100
return
101101
# Extract functions from methods.
102102
if hasattr(x, '__func__'):
@@ -118,35 +118,30 @@ def dis(x=None, *, file=None, depth=None, show_caches=False, adaptive=False,
118118
print("Disassembly of %s:" % name, file=file)
119119
try:
120120
dis(x1, file=file, depth=depth, show_caches=show_caches, adaptive=adaptive,
121-
show_offsets=show_offsets, show_positions=show_positions, show_jit=show_jit,
122-
show_block_bg=show_block_bg)
121+
show_offsets=show_offsets, show_positions=show_positions, show_jit=show_jit)
123122
except TypeError as msg:
124123
print("Sorry:", msg, file=file)
125124
print(file=file)
126125
elif hasattr(x, 'co_code'): # Code object
127126
_disassemble_recursive(x, file=file, depth=depth, show_caches=show_caches, adaptive=adaptive,
128-
show_offsets=show_offsets, show_positions=show_positions, show_jit=show_jit,
129-
show_block_bg=show_block_bg)
127+
show_offsets=show_offsets, show_positions=show_positions, show_jit=show_jit)
130128
elif isinstance(x, (bytes, bytearray)): # Raw bytecode
131129
labels_map = _make_labels_map(x)
132130
label_width = 4 + len(str(len(labels_map)))
133131
formatter = Formatter(file=file,
134132
offset_width=len(str(max(len(x) - 2, 9999))) if show_offsets else 0,
135133
label_width=label_width,
136-
show_caches=show_caches,
137-
show_block_bg=show_block_bg)
134+
show_caches=show_caches)
138135
arg_resolver = ArgResolver(labels_map=labels_map)
139136
_disassemble_bytes(x, arg_resolver=arg_resolver, formatter=formatter)
140137
elif isinstance(x, str): # Source code
141138
_disassemble_str(x, file=file, depth=depth, show_caches=show_caches, adaptive=adaptive,
142-
show_offsets=show_offsets, show_positions=show_positions, show_jit=show_jit,
143-
show_block_bg=show_block_bg)
139+
show_offsets=show_offsets, show_positions=show_positions, show_jit=show_jit)
144140
else:
145141
raise TypeError("don't know how to disassemble %s objects" %
146142
type(x).__name__)
147143

148-
def distb(tb=None, *, file=None, show_caches=False, adaptive=False, show_offsets=False, show_positions=False, show_jit=False,
149-
show_block_bg=False):
144+
def distb(tb=None, *, file=None, show_caches=False, adaptive=False, show_offsets=False, show_positions=False, show_jit=False):
150145
"""Disassemble a traceback (default: last traceback)."""
151146
if tb is None:
152147
try:
@@ -158,8 +153,7 @@ def distb(tb=None, *, file=None, show_caches=False, adaptive=False, show_offsets
158153
raise RuntimeError("no last traceback to disassemble") from None
159154
while tb.tb_next: tb = tb.tb_next
160155
disassemble(tb.tb_frame.f_code, tb.tb_lasti, file=file, show_caches=show_caches, adaptive=adaptive,
161-
show_offsets=show_offsets, show_positions=show_positions, show_jit=show_jit,
162-
show_block_bg=show_block_bg)
156+
show_offsets=show_offsets, show_positions=show_positions, show_jit=show_jit)
163157

164158
# The inspect module interrogates this dictionary to build its
165159
# list of CO_* constants. It is also used by pretty_flags to
@@ -455,8 +449,7 @@ def _get_dis_theme():
455449
class Formatter:
456450

457451
def __init__(self, file=None, lineno_width=0, offset_width=0, label_width=0,
458-
line_offset=0, show_caches=False, *, show_positions=False,
459-
show_block_bg=False):
452+
line_offset=0, show_caches=False, *, show_positions=False):
460453
"""Create a Formatter
461454
462455
*file* where to write the output
@@ -475,8 +468,6 @@ def __init__(self, file=None, lineno_width=0, offset_width=0, label_width=0,
475468
self.label_width = label_width
476469
self.show_caches = show_caches
477470
self.show_positions = show_positions
478-
self.show_block_bg = show_block_bg
479-
self._alt_block = False # toggle between first/second alt block color
480471

481472
def print_instruction(self, instr, mark_as_current=False):
482473
self.print_instruction_line(instr, mark_as_current)
@@ -508,8 +499,6 @@ def print_instruction_line(self, instr, mark_as_current):
508499
instr.offset > 0)
509500
if new_source_line:
510501
print(file=self.file)
511-
if self.show_block_bg:
512-
self._alt_block = not self._alt_block
513502

514503
fields = []
515504
# Column: Source code locations information
@@ -559,14 +548,7 @@ def print_instruction_line(self, instr, mark_as_current):
559548
# Column: Opcode argument details
560549
if instr.argrepr:
561550
fields.append(f'{theme.argument_detail}(' + instr.argrepr + f'){theme.reset}')
562-
563-
line = ' '.join(fields).rstrip()
564-
565-
if self.show_block_bg:
566-
bg = theme.alt_block_first_bg if self._alt_block else theme.alt_block_second_bg
567-
line = bg + line.replace(theme.reset, theme.reset + bg) + "\x1b[K" + theme.reset
568-
569-
print(line, file=self.file)
551+
print(' '.join(fields).rstrip(), file=self.file)
570552

571553
def print_exception_table(self, exception_entries):
572554
file = self.file
@@ -855,8 +837,7 @@ def _get_instructions_bytes(code, linestarts=None, line_offset=0, co_positions=N
855837

856838

857839
def disassemble(co, lasti=-1, *, file=None, show_caches=False, adaptive=False,
858-
show_offsets=False, show_positions=False, show_jit=False,
859-
show_block_bg=False):
840+
show_offsets=False, show_positions=False, show_jit=False):
860841
"""Disassemble a code object."""
861842
linestarts = dict(findlinestarts(co))
862843
exception_entries = _parse_exception_table(co)
@@ -871,8 +852,7 @@ def disassemble(co, lasti=-1, *, file=None, show_caches=False, adaptive=False,
871852
offset_width=len(str(max(len(co.co_code) - 2, 9999))) if show_offsets else 0,
872853
label_width=label_width,
873854
show_caches=show_caches,
874-
show_positions=show_positions,
875-
show_block_bg=show_block_bg)
855+
show_positions=show_positions)
876856
arg_resolver = ArgResolver(co_consts=co.co_consts,
877857
names=co.co_names,
878858
varname_from_oparg=co._varname_from_oparg,
@@ -881,9 +861,8 @@ def disassemble(co, lasti=-1, *, file=None, show_caches=False, adaptive=False,
881861
exception_entries=exception_entries, co_positions=co.co_positions(),
882862
original_code=co.co_code, arg_resolver=arg_resolver, formatter=formatter)
883863

884-
def _disassemble_recursive(co, *, file=None, depth=None, show_caches=False, adaptive=False, show_offsets=False, show_positions=False, show_jit=False, show_block_bg=False):
885-
disassemble(co, file=file, show_caches=show_caches, adaptive=adaptive, show_offsets=show_offsets, show_positions=show_positions, show_jit=show_jit,
886-
show_block_bg=show_block_bg)
864+
def _disassemble_recursive(co, *, file=None, depth=None, show_caches=False, adaptive=False, show_offsets=False, show_positions=False, show_jit=False):
865+
disassemble(co, file=file, show_caches=show_caches, adaptive=adaptive, show_offsets=show_offsets, show_positions=show_positions, show_jit=show_jit)
887866
if depth is None or depth > 0:
888867
if depth is not None:
889868
depth = depth - 1
@@ -895,8 +874,7 @@ def _disassemble_recursive(co, *, file=None, depth=None, show_caches=False, adap
895874
_disassemble_recursive(
896875
x, file=file, depth=depth, show_caches=show_caches,
897876
adaptive=adaptive, show_offsets=show_offsets,
898-
show_positions=show_positions, show_jit=show_jit,
899-
show_block_bg=show_block_bg
877+
show_positions=show_positions, show_jit=show_jit
900878
)
901879

902880

@@ -1197,8 +1175,6 @@ def main(args=None):
11971175
help='show instruction positions')
11981176
parser.add_argument('-S', '--specialized', action='store_true',
11991177
help='show specialized bytecode')
1200-
parser.add_argument('-B', '--block-bg', action='store_true',
1201-
help='alternate background per source-line block')
12021178
parser.add_argument('infile', nargs='?', default='-')
12031179
args = parser.parse_args(args=args)
12041180
if args.infile == '-':
@@ -1210,8 +1186,7 @@ def main(args=None):
12101186
source = infile.read()
12111187
code = compile(source, name, "exec")
12121188
dis(code, show_caches=args.show_caches, adaptive=args.specialized,
1213-
show_offsets=args.show_offsets, show_positions=args.show_positions,
1214-
show_block_bg=args.block_bg)
1189+
show_offsets=args.show_offsets, show_positions=args.show_positions)
12151190

12161191
if __name__ == "__main__":
12171192
main()

0 commit comments

Comments
 (0)