summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@microsoft.com>2022-07-10 05:12:45 (GMT)
committerGitHub <noreply@github.com>2022-07-10 05:12:45 (GMT)
commite5c8ad3e1518f81f7651d82bbadf5af5e3f402a7 (patch)
tree19d19127769ee998471952a753dc2283148a285a /Python
parent7b5737a51ac2f67ab1c1c1fdee75fbb59fd123ea (diff)
downloadcpython-e5c8ad3e1518f81f7651d82bbadf5af5e3f402a7.zip
cpython-e5c8ad3e1518f81f7651d82bbadf5af5e3f402a7.tar.gz
cpython-e5c8ad3e1518f81f7651d82bbadf5af5e3f402a7.tar.bz2
[3.11] GH-94694: Fix column offsets for multi-line method lookups (GH-94721)
(cherry picked from commit 264b3ddfd561d97204ffb30be6a7d1fb0555e560)
Diffstat (limited to 'Python')
-rw-r--r--Python/compile.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/Python/compile.c b/Python/compile.c
index a71e7d3..42f3730 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -4788,8 +4788,15 @@ update_location_to_match_attr(struct compiler *c, expr_ty meth)
{
if (meth->lineno != meth->end_lineno) {
// Make start location match attribute
- c->u->u_lineno = meth->end_lineno;
- c->u->u_col_offset = meth->end_col_offset - (int)PyUnicode_GetLength(meth->v.Attribute.attr)-1;
+ c->u->u_lineno = c->u->u_end_lineno = meth->end_lineno;
+ int len = (int)PyUnicode_GET_LENGTH(meth->v.Attribute.attr);
+ if (len <= meth->end_col_offset) {
+ c->u->u_col_offset = meth->end_col_offset - len;
+ }
+ else {
+ // GH-94694: Somebody's compiling weird ASTs. Just drop the columns:
+ c->u->u_col_offset = c->u->u_end_col_offset = -1;
+ }
}
}