Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
string.maketrans() which actually works on bytes. (Also closes #5675.)
diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst
index a8c3146..72e2fb4 100644
--- a/Doc/library/stdtypes.rst
+++ b/Doc/library/stdtypes.rst
@@ -479,7 +479,7 @@
exponent.
-.. method:: float.fromhex(s)
+.. classmethod:: float.fromhex(s)
Class method to return the float represented by a hexadecimal
string *s*. The string *s* may have leading and trailing
@@ -967,7 +967,7 @@
'example.com'
-.. method:: str.maketrans(x[, y[, z]])
+.. staticmethod:: str.maketrans(x[, y[, z]])
This static method returns a translation table usable for :meth:`str.translate`.
@@ -1514,8 +1514,8 @@
The bytes and bytearray types have an additional class method:
-.. method:: bytes.fromhex(string)
- bytearray.fromhex(string)
+.. classmethod:: bytes.fromhex(string)
+ bytearray.fromhex(string)
This :class:`bytes` class method returns a bytes or bytearray object,
decoding the given string object. The string must contain two hexadecimal
@@ -1524,7 +1524,9 @@
>>> bytes.fromhex('f0 f1f2 ')
b'\xf0\xf1\xf2'
-The translate method differs in semantics from the version available on strings:
+
+The maketrans and translate methods differ in semantics from the versions
+available on strings:
.. method:: bytes.translate(table[, delete])
@@ -1533,8 +1535,7 @@
mapped through the given translation table, which must be a bytes object of
length 256.
- You can use the :func:`string.maketrans` helper function to create a
- translation table.
+ You can use the :func:`bytes.maketrans` method to create a translation table.
Set the *table* argument to ``None`` for translations that only delete
characters::
@@ -1543,6 +1544,16 @@
b'rd ths shrt txt'
+.. staticmethod:: bytes.maketrans(from, to)
+
+ This static method returns a translation table usable for
+ :meth:`bytes.translate` that will map each character in *from* into the
+ character at the same position in *to*; *from* and *to* must be bytes objects
+ and have the same length.
+
+ .. versionadded:: 3.1
+
+
.. _types-set:
Set Types --- :class:`set`, :class:`frozenset`
@@ -1847,7 +1858,7 @@
Return a shallow copy of the dictionary.
- .. method:: fromkeys(seq[, value])
+ .. classmethod:: fromkeys(seq[, value])
Create a new dictionary with keys from *seq* and values set to *value*.
diff --git a/Doc/library/string.rst b/Doc/library/string.rst
index 5867a5a..29bf160 100644
--- a/Doc/library/string.rst
+++ b/Doc/library/string.rst
@@ -548,13 +548,9 @@
delimiter), and it should appear last in the regular expression.
-String functions
+Helper functions
----------------
-The following functions are available to operate on string objects.
-They are not available as string methods.
-
-
.. function:: capwords(s)
Split the argument into words using :func:`split`, capitalize each word using
@@ -568,3 +564,6 @@
Return a translation table suitable for passing to :meth:`bytes.translate`,
that will map each character in *from* into the character at the same
position in *to*; *from* and *to* must have the same length.
+
+ .. deprecated:: 3.1
+ Use the :meth:`bytes.maketrans` static method instead.