diff options
author | Raymond Hettinger <python@rcn.com> | 2007-04-12 04:10:00 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2007-04-12 04:10:00 (GMT) |
commit | 4db5fe970c695c373c59ac7152eb07b07249b0b5 (patch) | |
tree | b245934756e45a1dbc07fae5a07481373e560106 /Lib | |
parent | 51761806105a4cc2f58325f46a6d33c8144ad617 (diff) | |
download | cpython-4db5fe970c695c373c59ac7152eb07b07249b0b5.zip cpython-4db5fe970c695c373c59ac7152eb07b07249b0b5.tar.gz cpython-4db5fe970c695c373c59ac7152eb07b07249b0b5.tar.bz2 |
SF 1193128: Let str.translate(None) be an identity transformation
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/string.py | 2 | ||||
-rw-r--r-- | Lib/test/string_tests.py | 3 |
2 files changed, 4 insertions, 1 deletions
diff --git a/Lib/string.py b/Lib/string.py index 921bd8b..9e3cc41 100644 --- a/Lib/string.py +++ b/Lib/string.py @@ -487,7 +487,7 @@ def translate(s, table, deletions=""): deletions argument is not allowed for Unicode strings. """ - if deletions: + if deletions or table is None: return s.translate(table, deletions) else: # Add s[:0] so that if s is Unicode and table is an 8-bit string, diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py index 1aa68de..16161f3 100644 --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -1096,6 +1096,9 @@ class MixinStrStringUserStringTest: self.checkequal('Abc', 'abc', 'translate', table) self.checkequal('xyz', 'xyz', 'translate', table) self.checkequal('yz', 'xyz', 'translate', table, 'x') + self.checkequal('yx', 'zyzzx', 'translate', None, 'z') + self.checkequal('zyzzx', 'zyzzx', 'translate', None, '') + self.checkequal('zyzzx', 'zyzzx', 'translate', None) self.checkraises(ValueError, 'xyz', 'translate', 'too short', 'strip') self.checkraises(ValueError, 'xyz', 'translate', 'too short') |