Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On python 3.12 fstrings with \n are being escaped #549

Open
frmdstryr opened this issue Apr 13, 2024 · 2 comments
Open

On python 3.12 fstrings with \n are being escaped #549

frmdstryr opened this issue Apr 13, 2024 · 2 comments

Comments

@frmdstryr
Copy link
Contributor

frmdstryr commented Apr 13, 2024

The newline is here is being escaped and output as \n instead of a newline for some reason in 3.12.

x = 1
print(f"{x}\n{x}")    

It prints

1\n1

But it should be

1
1

Edit: Simplify example

frmdstryr added a commit to frmdstryr/enaml that referenced this issue Apr 15, 2024
@MatthieuDartiailh
Copy link
Member

The fact that the current parser produces the same AST as the Python parser but the output differs leaves me perplex. I will try to look into it.

@MatthieuDartiailh
Copy link
Member

Python is playing some funny games here:

>>> ast.unparse(ast.parse(r"""'a\n'"""))  
'"""a\n"""'
>>> eval(ast.unparse(ast.parse(r"""'a\n'""")))  
'a\n'
>>> ast.unparse(ast.parse(r"""f'a\n'"""))        
"f'a\\n'"
>>> eval(ast.unparse(ast.parse(r"""f'a\n'""")))  
'a\n'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants