Author: Armin Rigo <ar...@tunes.org> Branch: py3.5-fstring-pep498 Changeset: r89726:086cef12dead Date: 2017-01-24 12:19 +0100 http://bitbucket.org/pypy/pypy/changeset/086cef12dead/
Log: test and fix + tweaks diff --git a/pypy/interpreter/astcompiler/fstring.py b/pypy/interpreter/astcompiler/fstring.py --- a/pypy/interpreter/astcompiler/fstring.py +++ b/pypy/interpreter/astcompiler/fstring.py @@ -50,8 +50,10 @@ consts.PyCF_SOURCE_IS_UTF8 | consts.PyCF_IGNORE_COOKIE, optimize=astbuilder.compile_info.optimize) - parse_tree = astbuilder.recursive_parser.parse_source(source, info) - return ast_from_node(astbuilder.space, parse_tree, info) + parser = astbuilder.recursive_parser + parse_tree = parser.parse_source(source, info) + return ast_from_node(astbuilder.space, parse_tree, info, + recursive_parser=parser) def unexpected_end_of_string(astbuilder, atom_node): @@ -257,7 +259,8 @@ fstr.current_index = i literal = builder.build() - if not fstr.raw_mode: + if not fstr.raw_mode and u'\\' in literal: + literal = literal.encode('utf-8') literal = unicodehelper.decode_unicode_escape(astbuilder.space, literal) return literal @@ -281,7 +284,10 @@ def parse_f_string(astbuilder, joined_pieces, fstr, atom_node, rec=0): - space = astbuilder.space + # In our case, parse_f_string() and fstring_find_literal_and_expr() + # could be merged into a single function with a clearer logic. It's + # done this way to follow CPython's source code more closely. + while True: literal, expr = fstring_find_literal_and_expr(astbuilder, fstr, atom_node, rec) diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py b/pypy/interpreter/astcompiler/test/test_compiler.py --- a/pypy/interpreter/astcompiler/test/test_compiler.py +++ b/pypy/interpreter/astcompiler/test/test_compiler.py @@ -1184,6 +1184,8 @@ yield self.st, """z=f'{"}"}'""", 'z', '}' + yield self.st, """z=f'{f"{0}"*3}'""", 'z', '000' + def test_fstring_error(self): raises(SyntaxError, self.run, "f'{}'") raises(SyntaxError, self.run, "f'{ \t }'") _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit