Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate

string.maketrans() which actually works on bytes.  (Also closes #5675.)
This commit is contained in:
Georg Brandl 2009-04-12 15:51:51 +00:00
parent 78532baeab
commit abc387747d
11 changed files with 134 additions and 32 deletions

View file

@ -49,6 +49,9 @@ def maketrans(frm: bytes, to: bytes) -> bytes:
mapped to the byte at the same position in to.
The strings frm and to must be of the same length.
"""
import warnings
warnings.warn("string.maketrans is deprecated, use bytes.maketrans instead",
DeprecationWarning)
if len(frm) != len(to):
raise ValueError("maketrans arguments must have same length")
if not (isinstance(frm, bytes) and isinstance(to, bytes)):