[3.11] gh-99103: Normalize specialized traceback anchors against the current line (#99423)

[3.11] gh-99103: Normalize specialized traceback anchors against the current line (GH-99145)

Automerge-Triggered-By: GH:isidentical.
(cherry picked from commit 57be545959)

Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
This commit is contained in:
Batuhan Taskaya 2022-11-22 01:16:12 +03:00 committed by GitHub
parent 2d5f4ba174
commit a3480ec795
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 5 deletions

View file

@ -705,8 +705,13 @@ extract_anchors_from_line(PyObject *filename, PyObject *line,
done:
if (res > 0) {
*left_anchor += start_offset;
*right_anchor += start_offset;
// Normalize the AST offsets to byte offsets and adjust them with the
// start of the actual line (instead of the source code segment).
assert(segment != NULL);
assert(*left_anchor >= 0);
assert(*right_anchor >= 0);
*left_anchor = _PyPegen_byte_offset_to_character_offset(segment, *left_anchor) + start_offset;
*right_anchor = _PyPegen_byte_offset_to_character_offset(segment, *right_anchor) + start_offset;
}
Py_XDECREF(segment);
if (arena) {