[pypy-commit] pypy py3.7: remove the f, if possible
cfbolz
pypy.commits at gmail.com
Mon Jan 6 13:51:57 EST 2020
Author: Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>
Branch: py3.7
Changeset: r98455:fcec4f8b9fb2
Date: 2020-01-06 13:57 +0100
http://bitbucket.org/pypy/pypy/changeset/fcec4f8b9fb2/
Log: remove the f, if possible
diff --git a/pypy/interpreter/astcompiler/test/test_unparse.py b/pypy/interpreter/astcompiler/test/test_unparse.py
--- a/pypy/interpreter/astcompiler/test/test_unparse.py
+++ b/pypy/interpreter/astcompiler/test/test_unparse.py
@@ -155,7 +155,7 @@
self.check('lambda a, **b: 45')
def test_fstrings(self):
- #self.check('f"abc"', '"abc"')
+ self.check('f"abc"', "'abc'")
self.check("f'{{{a}'", "f'{{{a}'")
self.check("f'{{{a}'", "f'{{{a}'")
self.check("f'{x+1!a}'", "f'{x + 1!a}'")
diff --git a/pypy/interpreter/astcompiler/unparse.py b/pypy/interpreter/astcompiler/unparse.py
--- a/pypy/interpreter/astcompiler/unparse.py
+++ b/pypy/interpreter/astcompiler/unparse.py
@@ -453,13 +453,16 @@
self.append_expr(node.body)
def visit_JoinedStr(self, node):
- # mess
+ need_f = False
subvisitor = FstringVisitor(self.space)
for i, elt in enumerate(node.values):
+ if not isinstance(elt, ast.Str):
+ need_f = True
elt.walkabout(subvisitor)
s = subvisitor.builder.build()
l = subvisitor.builder.getlength()
- self.append_ascii("f")
+ if need_f:
+ self.append_ascii("f")
self.append_w_str(self.space.repr(self.space.newutf8(s, l)))
More information about the pypy-commit
mailing list