Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Lib/test/test_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,13 @@ def test_maketrans_translate(self):
self.assertEqual("[a\xe9]".translate(str.maketrans({'a': '<\u20ac>'})),
"[<\u20ac>\xe9]")

# with frozendict
tbl = self.type2test.maketrans(frozendict({'s': 'S', 'T': 't'}))
self.assertEqual(tbl, {ord('s'): 'S', ord('T'): 't'})
self.assertEqual('sTan'.translate(tbl), 'Stan')
tbl = self.type2test.maketrans(frozendict({'a': None, 'b': '<i>'}))
self.checkequalnofix('<i><i><i>c', 'abababc', 'translate', tbl)

# invalid Unicode characters
invalid_char = 0x10ffff+1
for before in "a\xe9\u20ac\U0010ffff":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:meth:`str.maketrans` now accepts :class:`frozendict`.
2 changes: 1 addition & 1 deletion Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -13149,7 +13149,7 @@ unicode_maketrans_impl(PyObject *x, PyObject *y, PyObject *z)
const void *data;

/* x must be a dict */
if (!PyDict_CheckExact(x)) {
if (!PyAnyDict_CheckExact(x)) {
PyErr_SetString(PyExc_TypeError, "if you give only one argument "
"to maketrans it must be a dict");
goto err;
Expand Down
Loading