From 889683e173db85fbf49f419a18c1fea8924a3801 Mon Sep 17 00:00:00 2001 From: Chih-Hsuan Yen Date: Mon, 27 May 2019 00:37:36 +0800 Subject: [PATCH 1/3] bpo-37053: handle strings like u"bar" correctly in Tools/parser/unparse.py Constant.kind is added in https://bugs.python.org/issue36280. Current possible values for Constant.kind are "u" or None. For r'bar' and b'bar', Constant.kind value is None, so there's no need for special handling. --- Lib/test/test_tools/test_unparse.py | 5 +++++ Tools/parser/unparse.py | 2 ++ 2 files changed, 7 insertions(+) diff --git a/Lib/test/test_tools/test_unparse.py b/Lib/test/test_tools/test_unparse.py index f3386f5e31a2df..a958ebb51cc3d2 100644 --- a/Lib/test/test_tools/test_unparse.py +++ b/Lib/test/test_tools/test_unparse.py @@ -139,6 +139,11 @@ def test_fstrings(self): self.check_roundtrip(r"""f'{f"{0}"*3}'""") self.check_roundtrip(r"""f'{f"{y}"*3}'""") + def test_strings(self): + self.check_roundtrip("u'foo'") + self.check_roundtrip("r'foo'") + self.check_roundtrip("b'foo'") + def test_del_statement(self): self.check_roundtrip("del x, y, z") diff --git a/Tools/parser/unparse.py b/Tools/parser/unparse.py index 385902ef4bc5e7..a5cc000676b022 100644 --- a/Tools/parser/unparse.py +++ b/Tools/parser/unparse.py @@ -399,6 +399,8 @@ def _Constant(self, t): elif value is ...: self.write("...") else: + if t.kind == "u": + self.write("u") self._write_constant(t.value) def _List(self, t): From 913265ef64e7a03446dad2bacae2fc2a4ceb5515 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" Date: Sun, 26 May 2019 16:47:07 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Tools/Demos/2019-05-26-16-47-06.bpo-37053.-EYRuz.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Tools/Demos/2019-05-26-16-47-06.bpo-37053.-EYRuz.rst diff --git a/Misc/NEWS.d/next/Tools/Demos/2019-05-26-16-47-06.bpo-37053.-EYRuz.rst b/Misc/NEWS.d/next/Tools/Demos/2019-05-26-16-47-06.bpo-37053.-EYRuz.rst new file mode 100644 index 00000000000000..5320dc51f75036 --- /dev/null +++ b/Misc/NEWS.d/next/Tools/Demos/2019-05-26-16-47-06.bpo-37053.-EYRuz.rst @@ -0,0 +1 @@ +Handle strings like u"bar" correctly in Tools/parser/unparse.py. Patch by Chih-Hsuan Yen. \ No newline at end of file From 64666dbe8b97e99909978f601436bdc9c7bc8bc4 Mon Sep 17 00:00:00 2001 From: Chih-Hsuan Yen Date: Mon, 27 May 2019 00:49:36 +0800 Subject: [PATCH 3/3] Move the news file to the correct path --- .../2019-05-26-16-47-06.bpo-37053.-EYRuz.rst | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Misc/NEWS.d/next/{Tools/Demos => Tools-Demos}/2019-05-26-16-47-06.bpo-37053.-EYRuz.rst (100%) diff --git a/Misc/NEWS.d/next/Tools/Demos/2019-05-26-16-47-06.bpo-37053.-EYRuz.rst b/Misc/NEWS.d/next/Tools-Demos/2019-05-26-16-47-06.bpo-37053.-EYRuz.rst similarity index 100% rename from Misc/NEWS.d/next/Tools/Demos/2019-05-26-16-47-06.bpo-37053.-EYRuz.rst rename to Misc/NEWS.d/next/Tools-Demos/2019-05-26-16-47-06.bpo-37053.-EYRuz.rst