diff options
author | Batuhan Taskaya <batuhan@python.org> | 2021-07-15 23:38:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-15 23:38:11 (GMT) |
commit | 919ad537510fdc2c750109e0bc4eceea234324b2 (patch) | |
tree | 203dc2bd7d3beeb8623027e0fbead3addac15808 | |
parent | 074e7659f208051b6b973f7fdb654dd22b93aaa2 (diff) | |
download | cpython-919ad537510fdc2c750109e0bc4eceea234324b2.zip cpython-919ad537510fdc2c750109e0bc4eceea234324b2.tar.gz cpython-919ad537510fdc2c750109e0bc4eceea234324b2.tar.bz2 |
bpo-43950: make BinOp specializations more reliable (GH-27126)
-rw-r--r-- | Lib/test/test_traceback.py | 38 | ||||
-rw-r--r-- | Lib/traceback.py | 2 | ||||
-rw-r--r-- | Python/traceback.c | 2 |
3 files changed, 40 insertions, 2 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 8baf38c..402f773 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -485,6 +485,44 @@ class TracebackErrorLocationCaretTests(unittest.TestCase): ) 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): diff --git a/Lib/traceback.py b/Lib/traceback.py index ec5e20d..40d736a 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -496,7 +496,7 @@ class StackSummary(list): 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 diff --git a/Python/traceback.c b/Python/traceback.c index 199d3ea..643096c 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -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; } |