Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aaf47ca

Browse files
yan12125miss-islington
authored andcommitted
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
1 parent 91f4380 commit aaf47ca

3 files changed

Lines changed: 8 additions & 0 deletions

File tree

Lib/test/test_tools/test_unparse.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ def test_fstrings(self):
139139
self.check_roundtrip(r"""f'{f"{0}"*3}'""")
140140
self.check_roundtrip(r"""f'{f"{y}"*3}'""")
141141

142+
def test_strings(self):
143+
self.check_roundtrip("u'foo'")
144+
self.check_roundtrip("r'foo'")
145+
self.check_roundtrip("b'foo'")
146+
142147
def test_del_statement(self):
143148
self.check_roundtrip("del x, y, z")
144149

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Handle strings like u"bar" correctly in Tools/parser/unparse.py. Patch by Chih-Hsuan Yen.

Tools/parser/unparse.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ def _Constant(self, t):
399399
elif value is ...:
400400
self.write("...")
401401
else:
402+
if t.kind == "u":
403+
self.write("u")
402404
self._write_constant(t.value)
403405

404406
def _List(self, t):

0 commit comments

Comments
 (0)