Skip to content

Commit 1e409fb

Browse files
committed
Add Python version since deprecation in base64 methods.
Allow developers to not have to either test on N Python versions or looked through multiple versions of the docs to know whether they can easily update.
1 parent 1d4601c commit 1e409fb

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

Doc/library/base64.rst

+13-4
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,18 @@ The legacy interface:
237237

238238

239239
.. function:: decodebytes(s)
240-
decodestring(s)
241240

242241
Decode the :term:`bytes-like object` *s*, which must contain one or more
243242
lines of base64 encoded data, and return the decoded :class:`bytes`.
244-
``decodestring`` is a deprecated alias.
245243

246244
.. versionadded:: 3.1
247245

246+
.. function:: decodestring(s)
247+
248+
Deprecated alias of :func:`decodebytes`
249+
250+
.. deprecated:: 3.1
251+
248252

249253
.. function:: encode(input, output)
250254

@@ -257,14 +261,19 @@ The legacy interface:
257261

258262

259263
.. function:: encodebytes(s)
260-
encodestring(s)
261264

262265
Encode the :term:`bytes-like object` *s*, which can contain arbitrary binary
263266
data, and return :class:`bytes` containing the base64-encoded data, with newlines
264267
(``b'\n'``) inserted after every 76 bytes of output, and ensuring that
265268
there is a trailing newline, as per :rfc:`2045` (MIME).
266269

267-
``encodestring`` is a deprecated alias.
270+
.. versionadded:: 3.1
271+
272+
.. function:: encodestring(s)
273+
274+
Deprecated alias of :func:`encodebytes`
275+
276+
.. deprecated:: 3.1
268277

269278

270279
An example usage of the module:

Lib/base64.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,8 @@ def encodebytes(s):
541541
def encodestring(s):
542542
"""Legacy alias of encodebytes()."""
543543
import warnings
544-
warnings.warn("encodestring() is a deprecated alias, use encodebytes()",
544+
warnings.warn("encodestring() is a deprecated alias since 3.1, "
545+
"use encodebytes()",
545546
DeprecationWarning, 2)
546547
return encodebytes(s)
547548

@@ -554,7 +555,8 @@ def decodebytes(s):
554555
def decodestring(s):
555556
"""Legacy alias of decodebytes()."""
556557
import warnings
557-
warnings.warn("decodestring() is a deprecated alias, use decodebytes()",
558+
warnings.warn("decodestring() is a deprecated alias since Python 3.1, "
559+
"use decodebytes()",
558560
DeprecationWarning, 2)
559561
return decodebytes(s)
560562

Lib/test/test_base64.py

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ def check_type_errors(self, f):
1818
int_data = memoryview(b"1234").cast('I')
1919
self.assertRaises(TypeError, f, int_data)
2020

21+
def test_encodestring_warns(self):
22+
with self.assertWarns(DeprecationWarning):
23+
base64.encodestring(b"www.python.org")
24+
25+
def test_decodestring_warns(self):
26+
with self.assertWarns(DeprecationWarning):
27+
base64.decodestring(b"d3d3LnB5dGhvbi5vcmc=\n")
28+
2129
def test_encodebytes(self):
2230
eq = self.assertEqual
2331
eq(base64.encodebytes(b"www.python.org"), b"d3d3LnB5dGhvbi5vcmc=\n")

0 commit comments

Comments
 (0)