◐ Shell
clean mode source ↗

Message 361456 - Python tracker

When concatenating f-strings, if there is an expression in any STRING node other than the first, col_offset of the parsed expression has a wrong value.

For example, parsing f"hello" f"{world}" outputs the following AST:

Module(
    body=[
        Expr(
            value=JoinedStr(
                values=[
                    Constant(
                        value="hello",
                        kind=None,
                        lineno=1,
                        col_offset=0,
                        end_lineno=1,
                        end_col_offset=19,
                    ),
                    FormattedValue(
                        value=Name(
                            id="world",
                            ctx=Load(),
                            lineno=1,
                            *col_offset=1,*
                            end_lineno=1,
                            *end_col_offset=6,*
                        ),
                        conversion=-1,
                        format_spec=None,
                        lineno=1,
                        col_offset=0,
                        end_lineno=1,
                        end_col_offset=19,
                    ),
                ],
                lineno=1,
                col_offset=0,
                end_lineno=1,
                end_col_offset=19,
            ),
            lineno=1,
            col_offset=0,
            end_lineno=1,
            end_col_offset=19,
        )
    ],
    type_ignores=[],
)

Here, col_offset and end_col_offset are wrong in the parsed NAME 'world'.