Skip to content

ast.unparse is not working correctly for strings with multiple quotes #108843

Description

@sunmy2019

Bug report

CPython versions tested on:

3.11

Operating systems tested on:

macOS

A clear and concise description of the bug:

During the implementation of #108553, I discovered this bug in the original implementation.

Due to the new syntax, the fix for 3.12 above cannot be reused for 3.11 and below.

importasts="f\"'''{1}\\\"\\\"\\\"\" "print(s)
eval(s)
s=ast.parse(s)
s1=ast.unparse(s)
print(s1)
eval(s1)

output:

f"'''{1}\"\"\""f''''{1}"""'Traceback (most recent call last): File "/Users/xxx/work/cpython/a.py", line 10, in <module> eval(s1) File "<string>", line 1 f''''{1}"""'^SyntaxError: unterminatedtriple-quotedstringliteral (detectedatline1)

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions