Skip to content

Commit dd5a391

Browse files
committed
Fix invalid column math
1 parent 937a3db commit dd5a391

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Python/compile.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4737,7 +4737,19 @@ update_location_to_match_attr(struct compiler *c, expr_ty meth)
47374737
if (meth->lineno != meth->end_lineno) {
47384738
// Make start location match attribute
47394739
c->u->u_loc.lineno = meth->end_lineno;
4740-
c->u->u_loc.col_offset = meth->end_col_offset - (int)PyUnicode_GetLength(meth->v.Attribute.attr)-1;
4740+
int len = (int)PyUnicode_GET_LENGTH(meth->v.Attribute.attr);
4741+
// The dot may or not be on this line. Don't try to include it in the
4742+
// column span, it's more trouble than it's worth:
4743+
if (len <= meth->end_col_offset) {
4744+
// |---- end_col_offset
4745+
// .method(...)
4746+
// |---------- new col_offset
4747+
c->u->u_loc.col_offset = meth->end_col_offset - len;
4748+
}
4749+
else {
4750+
// GH-94694: Somebody's compiling weird ASTs. Just drop the columns:
4751+
c->u->u_loc.col_offset = c->u->u_loc.end_col_offset = -1;
4752+
}
47414753
}
47424754
}
47434755

0 commit comments

Comments
 (0)