[Python-checkins] bpo-37053: handle strings like u"bar" correctly in Tools/parser/unparse.py (GH-13583)
Miss Islington (bot)
webhook-mailer at python.org
Sun May 26 13:08:24 EDT 2019
https://github.com/python/cpython/commit/aaf47caf35984e614d93bd8bea5227df55e0e3e6
commit: aaf47caf35984e614d93bd8bea5227df55e0e3e6
branch: master
author: Chih-Hsuan Yen <yan12125 at gmail.com>
committer: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
date: 2019年05月26日T10:08:19-07:00
summary:
bpo-37053: handle strings like u"bar" correctly in Tools/parser/unparse.py (GH-13583)
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.
https://bugs.python.org/issue37053
files:
A Misc/NEWS.d/next/Tools-Demos/2019-05-26-16-47-06.bpo-37053.-EYRuz.rst
M Lib/test/test_tools/test_unparse.py
M Tools/parser/unparse.py
diff --git a/Lib/test/test_tools/test_unparse.py b/Lib/test/test_tools/test_unparse.py
index f3386f5e31a2..a958ebb51cc3 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/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 000000000000..5320dc51f750
--- /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
diff --git a/Tools/parser/unparse.py b/Tools/parser/unparse.py
index 385902ef4bc5..a5cc000676b0 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):
More information about the Python-checkins
mailing list