mirror of
https://github.com/python/cpython
synced 2024-09-16 03:29:57 +00:00
bpo-43950: make BinOp specializations more reliable (GH-27126)
This commit is contained in:
parent
074e7659f2
commit
919ad53751
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue