|
4 | 4 | import types |
5 | 5 | import collections |
6 | 6 | import io |
| 7 | +from fileinput import lineno |
7 | 8 |
|
8 | 9 | from opcode import * |
9 | 10 | from opcode import ( |
@@ -436,6 +437,8 @@ def __init__(self, file=None, lineno_width=0, offset_width=0, positions_width=0, |
436 | 437 | *positions_width* sets the width of the instruction positions field (0 omits it) |
437 | 438 | *label_width* sets the width of the label field |
438 | 439 | *show_caches* is a boolean indicating whether to display cache lines |
| 440 | +
|
| 441 | + If *positions_width* is specified, *lineno_width* is ignored. |
439 | 442 | """ |
440 | 443 | self.file = file |
441 | 444 | self.lineno_width = lineno_width |
@@ -465,26 +468,28 @@ def print_instruction(self, instr, mark_as_current=False): |
465 | 468 | def print_instruction_line(self, instr, mark_as_current): |
466 | 469 | """Format instruction details for inclusion in disassembly output.""" |
467 | 470 | lineno_width = self.lineno_width |
468 | | - positions_wdith = self.positions_width |
| 471 | + positions_width = self.positions_width |
469 | 472 | offset_width = self.offset_width |
470 | 473 | label_width = self.label_width |
471 | 474 |
|
472 | | - new_source_line = (lineno_width > 0 and |
| 475 | + new_source_line = ((lineno_width > 0 or positions_width > 0) and |
473 | 476 | instr.starts_line and |
474 | 477 | instr.offset > 0) |
475 | 478 | if new_source_line: |
476 | 479 | print(file=self.file) |
477 | 480 |
|
478 | 481 | fields = [] |
479 | 482 | # Column: Source code line number |
480 | | - if lineno_width or positions_wdith: |
481 | | - if positions_wdith: |
| 483 | + if lineno_width or positions_width: |
| 484 | + if positions_width: |
| 485 | + # reporting positions instead of just line numbers |
| 486 | + assert lineno_width > 0 |
482 | 487 | if instr_positions := instr.positions: |
483 | 488 | ps = tuple('?' if p is None else p for p in instr_positions) |
484 | 489 | positions_str = "%s:%s-%s:%s" % ps |
485 | | - fields.append(f'{positions_str:{positions_wdith}}') |
| 490 | + fields.append(f'{positions_str:{positions_width}}') |
486 | 491 | else: |
487 | | - fields.append(' ' * positions_wdith) |
| 492 | + fields.append(' ' * positions_width) |
488 | 493 | else: |
489 | 494 | if instr.starts_line: |
490 | 495 | lineno_fmt = "%%%dd" if instr.line_number is not None else "%%%ds" |
@@ -831,7 +836,6 @@ def _make_labels_map(original_code, exception_entries=()): |
831 | 836 | return labels_map |
832 | 837 |
|
833 | 838 | _NO_LINENO = ' --' |
834 | | -_NO_POSITION = ' ?:?-?:?' |
835 | 839 |
|
836 | 840 | def _get_lineno_width(linestarts): |
837 | 841 | if linestarts is None: |
|
0 commit comments