@@ -426,31 +426,23 @@ def __str__(self): |
426 | 426 |
|
427 | 427 | class Formatter: |
428 | 428 |
|
429 | | - def __init__(self, file=None, lineno_width=None, offset_width=0, label_width=0, |
430 | | - line_offset=0, show_caches=False, *, locations_width=0, |
431 | | - show_positions=False): |
| 429 | + def __init__(self, file=None, lineno_width=0, offset_width=0, label_width=0, |
| 430 | + line_offset=0, show_caches=False, *, show_positions=False): |
432 | 431 | """Create a Formatter |
433 | 432 |
|
434 | 433 | *file* where to write the output |
435 | | - *lineno_width* sets the width of the line number field (deprecated) |
| 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 |
437 | 436 | *label_width* sets the width of the label field |
438 | 437 | *show_caches* is a boolean indicating whether to display cache lines |
439 | | - *locations_width* sets the width of the instruction locations (0 omits it) |
440 | 438 | *show_positions* is a boolean indicating whether positions should be |
441 | | - reported instead of line numbers |
442 | | - """ |
443 | | - if lineno_width is not None: |
444 | | - import warnings |
445 | | - warnings.warn("The 'lineno_width' parameter is deprecated. It is " |
446 | | - "now ignored and will be removed in Python 3.16. " |
447 | | - "Use 'locations_width' instead.", |
448 | | - DeprecationWarning, stacklevel=2) |
| 439 | + reported instead of line numbers. |
449 | 440 |
|
| 441 | + If *show_positions* is true, then *lineno_width* should be computed |
| 442 | + accordingly. |
| 443 | + """ |
450 | 444 | self.file = file |
451 | | - # keep the attribute in case someone is still using it |
452 | | - self.lineno_width = 0 if lineno_width is None else lineno_width |
453 | | - self.locations_width = locations_width |
| 445 | + self.lineno_width = lineno_width |
454 | 446 | self.offset_width = offset_width |
455 | 447 | self.label_width = label_width |
456 | 448 | self.show_caches = show_caches |
@@ -476,35 +468,35 @@ def print_instruction(self, instr, mark_as_current=False): |
476 | 468 |
|
477 | 469 | def print_instruction_line(self, instr, mark_as_current): |
478 | 470 | """Format instruction details for inclusion in disassembly output.""" |
479 | | - locations_width = self.locations_width |
| 471 | + lineno_width = self.lineno_width |
480 | 472 | offset_width = self.offset_width |
481 | 473 | label_width = self.label_width |
482 | 474 |
|
483 | | - new_source_line = ((locations_width > 0) and |
| 475 | + new_source_line = ((lineno_width > 0) and |
484 | 476 | instr.starts_line and |
485 | 477 | instr.offset > 0) |
486 | 478 | if new_source_line: |
487 | 479 | print(file=self.file) |
488 | 480 |
|
489 | 481 | fields = [] |
490 | 482 | # Column: Source code locations information |
491 | | - if locations_width: |
| 483 | + if lineno_width: |
492 | 484 | if self.show_positions: |
493 | 485 | # reporting positions instead of just line numbers |
494 | 486 | if instr_positions := instr.positions: |
495 | 487 | ps = tuple('?' if p is None else p for p in instr_positions) |
496 | 488 | positions_str = f"{ps[0]}:{ps[2]}-{ps[1]}:{ps[3]}" |
497 | | - fields.append(f'{positions_str:{locations_width}}') |
| 489 | + fields.append(f'{positions_str:{lineno_width}}') |
498 | 490 | else: |
499 | | - fields.append(' ' * locations_width) |
| 491 | + fields.append(' ' * lineno_width) |
500 | 492 | else: |
501 | 493 | if instr.starts_line: |
502 | 494 | lineno_fmt = "%%%dd" if instr.line_number is not None else "%%%ds" |
503 | | - lineno_fmt = lineno_fmt % locations_width |
| 495 | + lineno_fmt = lineno_fmt % lineno_width |
504 | 496 | lineno = _NO_LINENO if instr.line_number is None else instr.line_number |
505 | 497 | fields.append(lineno_fmt % lineno) |
506 | 498 | else: |
507 | | - fields.append(' ' * locations_width) |
| 499 | + fields.append(' ' * lineno_width) |
508 | 500 | # Column: Label |
509 | 501 | if instr.label is not None: |
510 | 502 | lbl = f"L{instr.label}:" |
@@ -796,14 +788,14 @@ def disassemble(co, lasti=-1, *, file=None, show_caches=False, adaptive=False, |
796 | 788 | linestarts = dict(findlinestarts(co)) |
797 | 789 | exception_entries = _parse_exception_table(co) |
798 | 790 | if show_positions: |
799 | | - locations_width = _get_positions_width(co) |
| 791 | + lineno_width = _get_positions_width(co) |
800 | 792 | else: |
801 | | - locations_width = _get_lineno_width(linestarts) |
| 793 | + lineno_width = _get_lineno_width(linestarts) |
802 | 794 | labels_map = _make_labels_map(co.co_code, exception_entries=exception_entries) |
803 | 795 | label_width = 4 + len(str(len(labels_map))) |
804 | 796 | formatter = Formatter(file=file, |
| 797 | + lineno_width=lineno_width, |
805 | 798 | offset_width=len(str(max(len(co.co_code) - 2, 9999))) if show_offsets else 0, |
806 | | - locations_width=locations_width, |
807 | 799 | label_width=label_width, |
808 | 800 | show_caches=show_caches, |
809 | 801 | show_positions=show_positions) |
@@ -1079,14 +1071,14 @@ def dis(self): |
1079 | 1071 | code = _get_code_array(co, self.adaptive) |
1080 | 1072 | offset_width = len(str(max(len(code) - 2, 9999))) if self.show_offsets else 0 |
1081 | 1073 | if self.show_positions: |
1082 | | - locations_width = _get_positions_width(co) |
| 1074 | + lineno_width = _get_positions_width(co) |
1083 | 1075 | else: |
1084 | | - locations_width = _get_lineno_width(self._linestarts) |
| 1076 | + lineno_width = _get_lineno_width(self._linestarts) |
1085 | 1077 | labels_map = _make_labels_map(co.co_code, self.exception_entries) |
1086 | 1078 | label_width = 4 + len(str(len(labels_map))) |
1087 | 1079 | formatter = Formatter(file=output, |
| 1080 | + lineno_width=lineno_width, |
1088 | 1081 | offset_width=offset_width, |
1089 | | - locations_width=locations_width, |
1090 | 1082 | label_width=label_width, |
1091 | 1083 | line_offset=self._line_offset, |
1092 | 1084 | show_caches=self.show_caches, |
|