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

Skip to content

Commit 5c1ee17

Browse files
committed
Change the unicode.translate docstring to document that
Unicode strings (with arbitrary length) are allowed as entries in the unicode.translate mapping. Add a test case for multicharacter replacements. (Multicharacter replacements were enabled by the PEP 293 patch)
1 parent a04c3d8 commit 5c1ee17

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

Lib/test/test_unicode.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,8 @@ def test_fixup(s):
405405
test('translate', u"abababc", u'bbbc', {ord('a'):None})
406406
test('translate', u"abababc", u'iiic', {ord('a'):None, ord('b'):ord('i')})
407407
test('translate', u"abababc", u'iiix', {ord('a'):None, ord('b'):ord('i'), ord('c'):u'x'})
408+
test('translate', u"abababc", u'<i><i><i>c', {ord('a'):None, ord('b'):u'<i>'})
409+
test('translate', u"abababc", u'c', {ord('a'):None, ord('b'):u''})
408410

409411
# Contains:
410412
print 'Testing Unicode contains method...',

Objects/unicodeobject.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5610,8 +5610,9 @@ PyDoc_STRVAR(translate__doc__,
56105610
\n\
56115611
Return a copy of the string S, where all characters have been mapped\n\
56125612
through the given translation table, which must be a mapping of\n\
5613-
Unicode ordinals to Unicode ordinals or None. Unmapped characters\n\
5614-
are left untouched. Characters mapped to None are deleted.");
5613+
Unicode ordinals to Unicode ordinals, Unicode strings or None.\n\
5614+
Unmapped characters are left untouched. Characters mapped to None\n\
5615+
are deleted.");
56155616

56165617
static PyObject*
56175618
unicode_translate(PyUnicodeObject *self, PyObject *table)

0 commit comments

Comments
 (0)