summaryrefslogtreecommitdiff
path: root/Lib/string.py
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2017-02-09 16:08:17 +0100
committerNick Coghlan <ncoghlan@gmail.com>2017-02-09 16:08:17 +0100
commitc6180bb73c8c7c7f9d8ea9816487b710597b6fc1 (patch)
treefb4a5c18886537b4b7df46ed3b2aa579747ff507 /Lib/string.py
parent5e0114a832a903518c4af6983161c0c2a8942a24 (diff)
parent819a21a3a4aac38f32e1ba4f68bcef45591fa3f0 (diff)
downloadcpython-c6180bb73c8c7c7f9d8ea9816487b710597b6fc1.tar.gz
Merge issue #26355 fix from Python 3.5
Diffstat (limited to 'Lib/string.py')
-rw-r--r--Lib/string.py11
1 files changed, 3 insertions, 8 deletions
diff --git a/Lib/string.py b/Lib/string.py
index 89287c4c0a..c902007643 100644
--- a/Lib/string.py
+++ b/Lib/string.py
@@ -28,7 +28,7 @@ ascii_letters = ascii_lowercase + ascii_uppercase
digits = '0123456789'
hexdigits = digits + 'abcdef' + 'ABCDEF'
octdigits = '01234567'
-punctuation = """!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
+punctuation = r"""!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~"""
printable = digits + ascii_letters + punctuation + whitespace
# Functions which aren't available as string methods.
@@ -116,10 +116,7 @@ class Template(metaclass=_TemplateMetaclass):
# Check the most common path first.
named = mo.group('named') or mo.group('braced')
if named is not None:
- val = mapping[named]
- # We use this idiom instead of str() because the latter will
- # fail if val is a Unicode containing non-ASCII characters.
- return '%s' % (val,)
+ return str(mapping[named])
if mo.group('escaped') is not None:
return self.delimiter
if mo.group('invalid') is not None:
@@ -146,9 +143,7 @@ class Template(metaclass=_TemplateMetaclass):
named = mo.group('named') or mo.group('braced')
if named is not None:
try:
- # We use this idiom instead of str() because the latter
- # will fail if val is a Unicode containing non-ASCII
- return '%s' % (mapping[named],)
+ return str(mapping[named])
except KeyError:
return mo.group()
if mo.group('escaped') is not None: