MCPcopy Index your code
hub / github.com/RustPython/RustPython / _should_show_carets

Method _should_show_carets

Lib/traceback.py:712–743  ·  view source on GitHub ↗
(self, start_offset, end_offset, all_lines, anchors)

Source from the content-addressed store, hash-verified

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.

Callers 1

format_frame_summaryMethod · 0.95

Calls 7

suppressClass · 0.90
isinstanceFunction · 0.85
lenFunction · 0.85
parseMethod · 0.45
joinMethod · 0.45
lstripMethod · 0.45
rstripMethod · 0.45

Tested by

no test coverage detected