Skip to content

Commit

Permalink
Drop 3.8- functions
Browse files Browse the repository at this point in the history
  • Loading branch information
gaogaotiantian committed Oct 4, 2023
1 parent a7d9b87 commit 7244211
Showing 1 changed file with 1 addition and 42 deletions.
43 changes: 1 addition & 42 deletions src/objprint/frame_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7244211

Please sign in to comment.