Skip to content

Commit a19e48a

Browse files
committed
gh-118830: Bump DEFAULT_PROTOCOL to 5 (#118830)
1 parent 127c1d2 commit a19e48a

File tree

5 files changed

+22
-12
lines changed

5 files changed

+22
-12
lines changed

Doc/library/pickle.rst

+12-5
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,14 @@ to read the pickle produced.
156156

157157
* Protocol version 4 was added in Python 3.4. It adds support for very large
158158
objects, pickling more kinds of objects, and some data format
159-
optimizations. It is the default protocol starting with Python 3.8.
159+
optimizations. This was the default protocol in Python 3.8--3.14.
160160
Refer to :pep:`3154` for information about improvements brought by
161161
protocol 4.
162162

163163
* Protocol version 5 was added in Python 3.8. It adds support for out-of-band
164-
data and speedup for in-band data. Refer to :pep:`574` for information about
165-
improvements brought by protocol 5.
164+
data and speedup for in-band data. It is the default protocol starting with
165+
Python 3.14. Refer to :pep:`574` for information about improvements brought
166+
by protocol 5.
166167

167168
.. note::
168169
Serialization is a more primitive notion than persistence; although
@@ -199,8 +200,10 @@ The :mod:`pickle` module provides the following constants:
199200

200201
An integer, the default :ref:`protocol version <pickle-protocols>` used
201202
for pickling. May be less than :data:`HIGHEST_PROTOCOL`. Currently the
202-
default protocol is 4, first introduced in Python 3.4 and incompatible
203-
with previous versions.
203+
default protocol is 5, introduced in Python 3.8 and incompatible
204+
with previous versions. This version introduces support for out-of-band
205+
buffers, where :pep:`3118`-compatible data can be transmitted separately
206+
from the main pickle stream.
204207

205208
.. versionchanged:: 3.0
206209

@@ -210,6 +213,10 @@ The :mod:`pickle` module provides the following constants:
210213

211214
The default protocol is 4.
212215

216+
.. versionchanged:: 3.14
217+
218+
The default protocol is 5.
219+
213220
The :mod:`pickle` module provides the following functions to make the pickling
214221
process more convenient:
215222

Doc/whatsnew/3.14.rst

+2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ symtable
115115
Optimizations
116116
=============
117117

118+
* Set the default protocol version on the :mod:`pickle` module to 5.
119+
For more details, please see :ref:`pickle protocols <pickle-protocols>`.
118120

119121

120122

Lib/pickle.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
bytes_types = (bytes, bytearray)
5252

5353
# These are purely informational; no code uses these.
54-
format_version = "4.0" # File format version we write
54+
format_version = "5.0" # File format version we write
5555
compatible_formats = ["1.0", # Original protocol 0
5656
"1.1", # Protocol 0 with INST added
5757
"1.2", # Original protocol 1
@@ -68,7 +68,7 @@
6868
# The protocol we write by default. May be less than HIGHEST_PROTOCOL.
6969
# Only bump this if the oldest still supported version of Python already
7070
# includes it.
71-
DEFAULT_PROTOCOL = 4
71+
DEFAULT_PROTOCOL = 5
7272

7373
class PickleError(Exception):
7474
"""A common base class for the other pickling exceptions."""
@@ -408,7 +408,7 @@ def __init__(self, file, protocol=None, *, fix_imports=True,
408408
409409
The optional *protocol* argument tells the pickler to use the
410410
given protocol; supported protocols are 0, 1, 2, 3, 4 and 5.
411-
The default protocol is 4. It was introduced in Python 3.4, and
411+
The default protocol is 5. It was introduced in Python 3.8, and
412412
is incompatible with previous versions.
413413
414414
Specifying a negative protocol version selects the highest
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Bump :mod:`pickle` default protocol to ``5``.

Modules/_pickle.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class _pickle.UnpicklerMemoProxy "UnpicklerMemoProxyObject *" ""
4040
already includes it. */
4141
enum {
4242
HIGHEST_PROTOCOL = 5,
43-
DEFAULT_PROTOCOL = 4
43+
DEFAULT_PROTOCOL = 5
4444
};
4545

4646
#ifdef MS_WINDOWS
@@ -4693,7 +4693,7 @@ This takes a binary file for writing a pickle data stream.
46934693
46944694
The optional *protocol* argument tells the pickler to use the given
46954695
protocol; supported protocols are 0, 1, 2, 3, 4 and 5. The default
4696-
protocol is 4. It was introduced in Python 3.4, and is incompatible
4696+
protocol is 5. It was introduced in Python 3.8, and is incompatible
46974697
with previous versions.
46984698
46994699
Specifying a negative protocol version selects the highest protocol
@@ -7504,7 +7504,7 @@ be more efficient.
75047504
75057505
The optional *protocol* argument tells the pickler to use the given
75067506
protocol; supported protocols are 0, 1, 2, 3, 4 and 5. The default
7507-
protocol is 4. It was introduced in Python 3.4, and is incompatible
7507+
protocol is 5. It was introduced in Python 3.8, and is incompatible
75087508
with previous versions.
75097509
75107510
Specifying a negative protocol version selects the highest protocol
@@ -7575,7 +7575,7 @@ Return the pickled representation of the object as a bytes object.
75757575
75767576
The optional *protocol* argument tells the pickler to use the given
75777577
protocol; supported protocols are 0, 1, 2, 3, 4 and 5. The default
7578-
protocol is 4. It was introduced in Python 3.4, and is incompatible
7578+
protocol is 5. It was introduced in Python 3.8, and is incompatible
75797579
with previous versions.
75807580
75817581
Specifying a negative protocol version selects the highest protocol

0 commit comments

Comments
 (0)