Skip to content

Commit

Permalink
Try to handle _line to _lines in 3.13
Browse files Browse the repository at this point in the history
  • Loading branch information
acbart committed Dec 8, 2024
1 parent 2fc8591 commit 111a5d7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
24 changes: 19 additions & 5 deletions pedal/utilities/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os
import sys

from pedal.utilities.system import IS_AT_LEAST_PYTHON_310, IS_AT_LEAST_PYTHON_311, IS_SKULPT
from pedal.utilities.system import IS_AT_LEAST_PYTHON_310, IS_AT_LEAST_PYTHON_311, IS_AT_LEAST_PYTHON_313, IS_SKULPT
from pedal.core.location import Location

BuiltinKeyError = KeyError
Expand Down Expand Up @@ -179,14 +179,23 @@ def _fix_frame_line(self, frame):
original_lineno = frame.lineno
frame.lineno += self.line_offsets[frame.filename]
if original_lineno - 1 < len(self.original_code_lines):
frame._line = self.original_code_lines[original_lineno - 1]
if IS_AT_LEAST_PYTHON_313:
frame._lines = self.original_code_lines[original_lineno - 1]
else:
frame._line = self.original_code_lines[original_lineno - 1]
else:
frame._line = "# *line missing*"
if IS_AT_LEAST_PYTHON_313:
frame._lines = "# *line missing*"
else:
frame._line = "# *line missing*"
else:
# print(frame.filename, self.student_files, frame.lineno)
if frame.filename in self.student_files:
if frame.lineno - 1 < len(self.original_code_lines):
frame._line = self.student_files[frame.filename][frame.lineno - 1]
if IS_AT_LEAST_PYTHON_313:
frame._lines = self.student_files[frame.filename][frame.lineno - 1]
else:
frame._line = self.student_files[frame.filename][frame.lineno - 1]
else:
# Not actually possible in CPython, but Skulpt gives weird
# SyntaxErrors that are technically the "next" line.
Expand Down Expand Up @@ -266,7 +275,12 @@ def format_traceback(self, traceback_stack, formatter):
return formatter.traceback(traceback_message)

def format_line(self, formatter, frame):
if IS_AT_LEAST_PYTHON_311:
if IS_AT_LEAST_PYTHON_313:
# Renamed _line to _lines in 3.13
# https://github.com/python/cpython/commit/939fc6d6eab9b7ea8c244d513610dbdd556503a7
end_offset = frame.end_colno+1 if frame.lineno == frame.end_lineno else len(frame.line)
return formatter.python_code(frame.line, focus=Location(0, frame.colno + 1, 0, end_offset))
elif IS_AT_LEAST_PYTHON_311:
end_offset = frame.end_colno+1 if frame.lineno == frame.end_lineno else len(frame._line)
# Note: Need to use _line because in 3.10 and above, the line gets stripped.
# https://github.com/python/cpython/commit/5644c7b3ffd49bed58dc095be6e6148e0bb4431e
Expand Down
1 change: 1 addition & 0 deletions pedal/utilities/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
IS_AT_LEAST_PYTHON_39 = sys.version_info[:2] >= (3, 9)
IS_AT_LEAST_PYTHON_310 = sys.version_info[:2] >= (3, 10)
IS_AT_LEAST_PYTHON_311 = sys.version_info[:2] >= (3, 11)
IS_AT_LEAST_PYTHON_313 = sys.version_info[:2] >= (3, 13)
IS_SKULPT = sys.platform == 'skulpt'

0 comments on commit 111a5d7

Please sign in to comment.