Skip to content

bpo-43950: make BinOp specializations more reliable #27126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions Lib/test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,44 @@ def test_traceback_specialization_with_syntax_error(self):
)
self.assertEqual(result_lines, expected_error.splitlines())

def assertSpecialized(self, func, expected_specialization):
result_lines = self.get_exception(func)
specialization_line = result_lines[-1]
self.assertEqual(specialization_line.lstrip(), expected_specialization)

def test_specialization_variations(self):
self.assertSpecialized(lambda: 1/0,
"~^~")
self.assertSpecialized(lambda: 1/0/3,
"~^~")
self.assertSpecialized(lambda: 1 / 0,
"~~^~~")
self.assertSpecialized(lambda: 1 / 0 / 3,
"~~^~~")
self.assertSpecialized(lambda: 1/ 0,
"~^~~")
self.assertSpecialized(lambda: 1/ 0/3,
"~^~~")
self.assertSpecialized(lambda: 1 / 0,
"~~~~~^~~~")
self.assertSpecialized(lambda: 1 / 0 / 5,
"~~~~~^~~~")
self.assertSpecialized(lambda: 1 /0,
"~~^~")
self.assertSpecialized(lambda: 1//0,
"~^^~")
self.assertSpecialized(lambda: 1//0//4,
"~^^~")
self.assertSpecialized(lambda: 1 // 0,
"~~^^~~")
self.assertSpecialized(lambda: 1 // 0 // 4,
"~~^^~~")
self.assertSpecialized(lambda: 1 //0,
"~~^^~")
self.assertSpecialized(lambda: 1// 0,
"~^^~~")


@cpython_only
@requires_debug_ranges()
class CPythonTracebackErrorCaretTests(TracebackErrorLocationCaretTests):
Expand Down
2 changes: 1 addition & 1 deletion Lib/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ def format(self):

try:
anchors = _extract_caret_anchors_from_line_segment(
frame._original_line[colno - 1:end_colno]
frame._original_line[colno - 1:end_colno - 1]
)
except Exception:
anchors = None
Expand Down
2 changes: 1 addition & 1 deletion Python/traceback.c
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ extract_anchors_from_expr(const char *segment_str, expr_ty expr, Py_ssize_t *lef
case BinOp_kind: {
expr_ty left = expr->v.BinOp.left;
expr_ty right = expr->v.BinOp.right;
for (int i = left->end_col_offset + 1; i < right->col_offset; i++) {
for (int i = left->end_col_offset; i < right->col_offset; i++) {
if (IS_WHITESPACE(segment_str[i])) {
continue;
}
Expand Down