]> granicus.if.org Git - python/commitdiff
bpo-37053: handle strings like u"bar" correctly in Tools/parser/unparse.py (GH-13583)
authorChih-Hsuan Yen <yan12125@gmail.com>
Sun, 26 May 2019 17:08:20 +0000 (01:08 +0800)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 26 May 2019 17:08:19 +0000 (10:08 -0700)
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

Lib/test/test_tools/test_unparse.py
Misc/NEWS.d/next/Tools-Demos/2019-05-26-16-47-06.bpo-37053.-EYRuz.rst [new file with mode: 0644]
Tools/parser/unparse.py

index f3386f5e31a2df7c5209b60e41e8cb95aa62a9c8..a958ebb51cc3d27974e78901bda8b24b6f5e8619 100644 (file)
@@ -139,6 +139,11 @@ class UnparseTestCase(ASTTestCase):
         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 (file)
index 0000000..5320dc5
--- /dev/null
@@ -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
index 385902ef4bc5e7f82183041eefd7b038ed93e6ed..a5cc000676b0227e961213ca76f6219ac34bb5b4 100644 (file)
@@ -399,6 +399,8 @@ class Unparser:
         elif value is ...:
             self.write("...")
         else:
+            if t.kind == "u":
+                self.write("u")
             self._write_constant(t.value)
 
     def _List(self, t):