(self, start_offset, end_offset, all_lines, anchors)
| 710 | return ''.join(row) |
| 711 | |
| 712 | def _should_show_carets(self, start_offset, end_offset, all_lines, anchors): |
| 713 | with suppress(SyntaxError, ImportError): |
| 714 | import ast |
| 715 | tree = ast.parse('\n'.join(all_lines)) |
| 716 | if not tree.body: |
| 717 | return False |
| 718 | statement = tree.body[0] |
| 719 | value = None |
| 720 | def _spawns_full_line(value): |
| 721 | return ( |
| 722 | value.lineno == 1 |
| 723 | and value.end_lineno == len(all_lines) |
| 724 | and value.col_offset == start_offset |
| 725 | and value.end_col_offset == end_offset |
| 726 | ) |
| 727 | match statement: |
| 728 | case ast.Return(value=ast.Call()): |
| 729 | if isinstance(statement.value.func, ast.Name): |
| 730 | value = statement.value |
| 731 | case ast.Assign(value=ast.Call()): |
| 732 | if ( |
| 733 | len(statement.targets) == 1 and |
| 734 | isinstance(statement.targets[0], ast.Name) |
| 735 | ): |
| 736 | value = statement.value |
| 737 | if value is not None and _spawns_full_line(value): |
| 738 | return False |
| 739 | if anchors: |
| 740 | return True |
| 741 | if all_lines[0][:start_offset].lstrip() or all_lines[-1][end_offset:].rstrip(): |
| 742 | return True |
| 743 | return False |
| 744 | |
| 745 | def format(self, **kwargs): |
| 746 | """Format the stack ready for printing. |
no test coverage detected