Pretty print the head and tail ``n_lines`` of ``val``, and omit the middle part if the part has more than 3 lines. Returns: the formatted string.
(val: Any, n_lines: int = 20)
| 728 | |
| 729 | |
| 730 | def pprint_edges(val: Any, n_lines: int = 20) -> str: |
| 731 | """ |
| 732 | Pretty print the head and tail ``n_lines`` of ``val``, and omit the middle part if the part has more than 3 lines. |
| 733 | |
| 734 | Returns: the formatted string. |
| 735 | """ |
| 736 | val_str = pprint.pformat(val).splitlines(True) |
| 737 | n_lines = max(n_lines, 1) |
| 738 | if len(val_str) > n_lines * 2 + 3: |
| 739 | hidden_n = len(val_str) - n_lines * 2 |
| 740 | val_str = val_str[:n_lines] + [f"\n ... omitted {hidden_n} line(s)\n\n"] + val_str[-n_lines:] |
| 741 | return "".join(val_str) |
| 742 | |
| 743 | |
| 744 | def check_key_duplicates(ordered_pairs: Sequence[tuple[Any, Any]]) -> dict[Any, Any]: |