diff --git a/src/objprint/frame_analyzer.py b/src/objprint/frame_analyzer.py index 3c34504..7264396 100644 --- a/src/objprint/frame_analyzer.py +++ b/src/objprint/frame_analyzer.py @@ -60,48 +60,7 @@ def get_executing_function_call_str(self, frame: FrameType) -> Optional[str]: except OSError: return None - if sys.version_info < (3, 8): - return self.get_source_segment3637(source, node) - else: - return ast.get_source_segment(source, node) - - def get_source_segment3637(self, source: str, node: ast.AST) -> str: - if node.lineno is None or node.col_offset is None: # pragma: no cover - return None - lineno = node.lineno - 1 - lines = self._splitlines_no_ff(source) - first_line = lines[lineno].encode()[node.col_offset:].decode() - lines = lines[lineno + 1:] - lines.insert(0, first_line) - return "".join(lines) - - def _splitlines_no_ff(self, source: str) -> List[str]: # pragma: no cover - """Split a string into lines ignoring form feed and other chars. - This mimics how the Python parser splits source code. - - :copyright: Copyright 2008 by Armin Ronacher. - :license: Python License. - from https://github.com/python/cpython/blob/main/Lib/ast.py - license: https://github.com/python/cpython/blob/main/LICENSE - """ - idx = 0 - lines = [] - next_line = '' - while idx < len(source): - c = source[idx] - next_line += c - idx += 1 - # Keep \r\n together - if c == '\r' and idx < len(source) and source[idx] == '\n': - next_line += '\n' - idx += 1 - if c in '\r\n': - lines.append(next_line) - next_line = '' - - if next_line: - lines.append(next_line) - return lines + return ast.get_source_segment(source, node) def return_object(self, frame: Optional[FrameType]) -> bool: if frame is None: