nucleic / enaml

Declarative User Interfaces for Python
http://enaml.readthedocs.io/en/latest/
Other
1.53k stars 130 forks source link

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

Open frmdstryr opened 5 months ago

frmdstryr commented 5 months ago

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

MatthieuDartiailh commented 5 months ago

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 commented 5 months ago

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'