Kaydet (Commit) 70b5924e authored tarafından Batuhan Taşkaya's avatar Batuhan Taşkaya Kaydeden (comit) Berker Peksag

Add support for f-string debugging syntax (#139)

Fixes #138
üst d9e893eb
......@@ -584,7 +584,11 @@ class SourceGenerator(ExplicitNodeVisitor):
self.write(value.s.replace('{', '{{').replace('}', '}}'))
elif isinstance(value, ast.FormattedValue):
with self.delimit('{}'):
self.visit(value.value)
# expr_text used for f-string debugging syntax.
if getattr(value, 'expr_text', None):
self.write(value.expr_text)
else:
self.visit(value.value)
if value.conversion != -1:
self.write('!%s' % chr(value.conversion))
if value.format_spec is not None:
......
......@@ -21,6 +21,12 @@ New features
.. _`Issue 126`: https://github.com/berkerpeksag/astor/issues/126
.. _`PR 134`: https://github.com/berkerpeksag/astor/pull/134
* Support Python 3.8's f-string debugging syntax.
(Reported and fixed by Batuhan Taskaya in `Issue 138`_ and `PR 139`_.)
.. _`Issue 138`: https://github.com/berkerpeksag/astor/issues/138
.. _`PR 139`: https://github.com/berkerpeksag/astor/pull/139
Bug fixes
~~~~~~~~~
......
# coding: utf-8
"""
Part of the astor library for Python AST manipulation
......@@ -664,6 +665,19 @@ class CodegenTestCase(unittest.TestCase, Comparisons):
'''
self.assertSrcRoundtripsGtVer(source, (3, 6))
@unittest.skipUnless(sys.version_info >= (3, 8, 0, "alpha", 4),
"f-string debugging introduced in Python 3.8")
def test_fstring_debugging(self):
source = """
x = f'{5=}'
y = f'{5=!r}'
z = f'{3*x+15=}'
f'{x=:}'
f'{x=:.2f}'
f'alpha α {pi=} ω omega'
"""
self.assertAstRoundtripsGtVer(source, (3, 8))
def test_docstring_function(self):
source = '''
def f(arg):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment