FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-43950: make BinOp specializations more reliable by isidentical · Pull Request #27126 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
38 changes: 38 additions & 0 deletions Lib/test/test_traceback.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL