Skip to content

FSTRING Start is not preserved in AST causing issue in ast.unparse #140026

@Thamirawaran

Description

@Thamirawaran

Bug report

Bug description:

import ast
code = """
f"My name is {name}"
rf"My name is {name}"
"""
print(ast.dump(ast.parse(code), indent=4))
ast_obj = ast.parse(code)
print(ast.unparse(ast_obj))

output

Module(
    body=[
        Expr(
            value=JoinedStr(
                values=[
                    Constant(value='My name is '),
                    FormattedValue(
                        value=Name(id='name', ctx=Load()),
                        conversion=-1)])),
        Expr(
            value=JoinedStr(
                values=[
                    Constant(value='My name is '),
                    FormattedValue(
                        value=Name(id='name', ctx=Load()),
                        conversion=-1)]))],
    type_ignores=[])
f'My name is {name}'
f'My name is {name}'

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)pendingThe issue will be closed if no feedback is providedtopic-parsertype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions