bpo-40334: Fix shifting of nested f-strings in the new parser (GH-19771)

`JoinedStr`s and `FormattedValue also needs to be shifted, in order to correctly compute the location information of nested f-strings.
This commit is contained in:
Lysandros Nikolaou 2020-04-29 03:43:50 +03:00 committed by GitHub
parent ae00a5a885
commit 37af21b667
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -207,7 +207,6 @@ f'{a * f"-{x()}-"}'"""
call = binop.right.values[1].value
self.assertEqual(type(call), ast.Call)
self.assertEqual(call.lineno, 3)
if support.use_old_parser():
self.assertEqual(call.col_offset, 11)
def test_ast_line_numbers_duplicate_expression(self):

View File

@ -449,6 +449,15 @@ static void fstring_shift_children_locations(expr_ty n, int lineno, int col_offs
case Tuple_kind:
fstring_shift_seq_locations(n, n->v.Tuple.elts, lineno, col_offset);
break;
case JoinedStr_kind:
fstring_shift_seq_locations(n, n->v.JoinedStr.values, lineno, col_offset);
break;
case FormattedValue_kind:
shift_expr(n, n->v.FormattedValue.value, lineno, col_offset);
if (n->v.FormattedValue.format_spec) {
shift_expr(n, n->v.FormattedValue.format_spec, lineno, col_offset);
}
break;
default:
return;
}