[issue28002] Some f-strings do not round trip through Tools/parser/test_unparse.py

Rémi Lapeyre report at bugs.python.org
Mon May 6 10:42:37 EDT 2019


Rémi Lapeyre <remi.lapeyre at henki.fr> added the comment:

The issue is also present in Astor:



Python 3.7.3 (default, Mar 27 2019, 09:23:15) 
[Clang 10.0.1 (clang-1001.0.46.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ast
>>> tree = ast.parse("""
... f'''{"'"}'''
... """)
>>> import astor
>>> astor.to_source(tree)
'f"""{"\'"}"""\n'
>>> f"""{"\'"}"""
  File "<stdin>", line 1
SyntaxError: f-string expression part cannot include a backslash


The issue comes too from calling repr to format the inner string as it does not try to minimize the number of \.

----------
nosy: +remi.lapeyre

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue28002>
_______________________________________


More information about the Python-bugs-list mailing list