mirror of https://github.com/python/cpython
gh-118830: Bump pickle.DEFAULT_PROTOCOL to 5 (GH-119340)
This commit is contained in:
parent
a1df1b4439
commit
d66b06107b
|
@ -156,13 +156,14 @@ to read the pickle produced.
|
||||||
|
|
||||||
* Protocol version 4 was added in Python 3.4. It adds support for very large
|
* Protocol version 4 was added in Python 3.4. It adds support for very large
|
||||||
objects, pickling more kinds of objects, and some data format
|
objects, pickling more kinds of objects, and some data format
|
||||||
optimizations. It is the default protocol starting with Python 3.8.
|
optimizations. This was the default protocol in Python 3.8--3.13.
|
||||||
Refer to :pep:`3154` for information about improvements brought by
|
Refer to :pep:`3154` for information about improvements brought by
|
||||||
protocol 4.
|
protocol 4.
|
||||||
|
|
||||||
* Protocol version 5 was added in Python 3.8. It adds support for out-of-band
|
* Protocol version 5 was added in Python 3.8. It adds support for out-of-band
|
||||||
data and speedup for in-band data. Refer to :pep:`574` for information about
|
data and speedup for in-band data. It is the default protocol starting with
|
||||||
improvements brought by protocol 5.
|
Python 3.14. Refer to :pep:`574` for information about improvements brought
|
||||||
|
by protocol 5.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
Serialization is a more primitive notion than persistence; although
|
Serialization is a more primitive notion than persistence; although
|
||||||
|
@ -199,8 +200,10 @@ The :mod:`pickle` module provides the following constants:
|
||||||
|
|
||||||
An integer, the default :ref:`protocol version <pickle-protocols>` used
|
An integer, the default :ref:`protocol version <pickle-protocols>` used
|
||||||
for pickling. May be less than :data:`HIGHEST_PROTOCOL`. Currently the
|
for pickling. May be less than :data:`HIGHEST_PROTOCOL`. Currently the
|
||||||
default protocol is 4, first introduced in Python 3.4 and incompatible
|
default protocol is 5, introduced in Python 3.8 and incompatible
|
||||||
with previous versions.
|
with previous versions. This version introduces support for out-of-band
|
||||||
|
buffers, where :pep:`3118`-compatible data can be transmitted separately
|
||||||
|
from the main pickle stream.
|
||||||
|
|
||||||
.. versionchanged:: 3.0
|
.. versionchanged:: 3.0
|
||||||
|
|
||||||
|
@ -210,6 +213,10 @@ The :mod:`pickle` module provides the following constants:
|
||||||
|
|
||||||
The default protocol is 4.
|
The default protocol is 4.
|
||||||
|
|
||||||
|
.. versionchanged:: 3.14
|
||||||
|
|
||||||
|
The default protocol is 5.
|
||||||
|
|
||||||
The :mod:`pickle` module provides the following functions to make the pickling
|
The :mod:`pickle` module provides the following functions to make the pickling
|
||||||
process more convenient:
|
process more convenient:
|
||||||
|
|
||||||
|
|
|
@ -146,6 +146,12 @@ symtable
|
||||||
|
|
||||||
(Contributed by Bénédikt Tran in :gh:`120029`.)
|
(Contributed by Bénédikt Tran in :gh:`120029`.)
|
||||||
|
|
||||||
|
pickle
|
||||||
|
------
|
||||||
|
|
||||||
|
* Set the default protocol version on the :mod:`pickle` module to 5.
|
||||||
|
For more details, please see :ref:`pickle protocols <pickle-protocols>`.
|
||||||
|
|
||||||
|
|
||||||
Optimizations
|
Optimizations
|
||||||
=============
|
=============
|
||||||
|
@ -160,7 +166,6 @@ asyncio
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Deprecated
|
Deprecated
|
||||||
==========
|
==========
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ except ImportError:
|
||||||
bytes_types = (bytes, bytearray)
|
bytes_types = (bytes, bytearray)
|
||||||
|
|
||||||
# These are purely informational; no code uses these.
|
# These are purely informational; no code uses these.
|
||||||
format_version = "4.0" # File format version we write
|
format_version = "5.0" # File format version we write
|
||||||
compatible_formats = ["1.0", # Original protocol 0
|
compatible_formats = ["1.0", # Original protocol 0
|
||||||
"1.1", # Protocol 0 with INST added
|
"1.1", # Protocol 0 with INST added
|
||||||
"1.2", # Original protocol 1
|
"1.2", # Original protocol 1
|
||||||
|
@ -68,7 +68,7 @@ HIGHEST_PROTOCOL = 5
|
||||||
# The protocol we write by default. May be less than HIGHEST_PROTOCOL.
|
# The protocol we write by default. May be less than HIGHEST_PROTOCOL.
|
||||||
# Only bump this if the oldest still supported version of Python already
|
# Only bump this if the oldest still supported version of Python already
|
||||||
# includes it.
|
# includes it.
|
||||||
DEFAULT_PROTOCOL = 4
|
DEFAULT_PROTOCOL = 5
|
||||||
|
|
||||||
class PickleError(Exception):
|
class PickleError(Exception):
|
||||||
"""A common base class for the other pickling exceptions."""
|
"""A common base class for the other pickling exceptions."""
|
||||||
|
@ -408,7 +408,7 @@ class _Pickler:
|
||||||
|
|
||||||
The optional *protocol* argument tells the pickler to use the
|
The optional *protocol* argument tells the pickler to use the
|
||||||
given protocol; supported protocols are 0, 1, 2, 3, 4 and 5.
|
given protocol; supported protocols are 0, 1, 2, 3, 4 and 5.
|
||||||
The default protocol is 4. It was introduced in Python 3.4, and
|
The default protocol is 5. It was introduced in Python 3.8, and
|
||||||
is incompatible with previous versions.
|
is incompatible with previous versions.
|
||||||
|
|
||||||
Specifying a negative protocol version selects the highest
|
Specifying a negative protocol version selects the highest
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Bump :mod:`pickle` default protocol to ``5``.
|
|
@ -40,7 +40,7 @@ class _pickle.UnpicklerMemoProxy "UnpicklerMemoProxyObject *" ""
|
||||||
already includes it. */
|
already includes it. */
|
||||||
enum {
|
enum {
|
||||||
HIGHEST_PROTOCOL = 5,
|
HIGHEST_PROTOCOL = 5,
|
||||||
DEFAULT_PROTOCOL = 4
|
DEFAULT_PROTOCOL = 5
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
|
@ -4692,7 +4692,7 @@ This takes a binary file for writing a pickle data stream.
|
||||||
|
|
||||||
The optional *protocol* argument tells the pickler to use the given
|
The optional *protocol* argument tells the pickler to use the given
|
||||||
protocol; supported protocols are 0, 1, 2, 3, 4 and 5. The default
|
protocol; supported protocols are 0, 1, 2, 3, 4 and 5. The default
|
||||||
protocol is 4. It was introduced in Python 3.4, and is incompatible
|
protocol is 5. It was introduced in Python 3.8, and is incompatible
|
||||||
with previous versions.
|
with previous versions.
|
||||||
|
|
||||||
Specifying a negative protocol version selects the highest protocol
|
Specifying a negative protocol version selects the highest protocol
|
||||||
|
@ -4725,7 +4725,7 @@ static int
|
||||||
_pickle_Pickler___init___impl(PicklerObject *self, PyObject *file,
|
_pickle_Pickler___init___impl(PicklerObject *self, PyObject *file,
|
||||||
PyObject *protocol, int fix_imports,
|
PyObject *protocol, int fix_imports,
|
||||||
PyObject *buffer_callback)
|
PyObject *buffer_callback)
|
||||||
/*[clinic end generated code: output=0abedc50590d259b input=a7c969699bf5dad3]*/
|
/*[clinic end generated code: output=0abedc50590d259b input=cddc50f66b770002]*/
|
||||||
{
|
{
|
||||||
/* In case of multiple __init__() calls, clear previous content. */
|
/* In case of multiple __init__() calls, clear previous content. */
|
||||||
if (self->write != NULL)
|
if (self->write != NULL)
|
||||||
|
@ -7507,7 +7507,7 @@ be more efficient.
|
||||||
|
|
||||||
The optional *protocol* argument tells the pickler to use the given
|
The optional *protocol* argument tells the pickler to use the given
|
||||||
protocol; supported protocols are 0, 1, 2, 3, 4 and 5. The default
|
protocol; supported protocols are 0, 1, 2, 3, 4 and 5. The default
|
||||||
protocol is 4. It was introduced in Python 3.4, and is incompatible
|
protocol is 5. It was introduced in Python 3.8, and is incompatible
|
||||||
with previous versions.
|
with previous versions.
|
||||||
|
|
||||||
Specifying a negative protocol version selects the highest protocol
|
Specifying a negative protocol version selects the highest protocol
|
||||||
|
@ -7533,7 +7533,7 @@ static PyObject *
|
||||||
_pickle_dump_impl(PyObject *module, PyObject *obj, PyObject *file,
|
_pickle_dump_impl(PyObject *module, PyObject *obj, PyObject *file,
|
||||||
PyObject *protocol, int fix_imports,
|
PyObject *protocol, int fix_imports,
|
||||||
PyObject *buffer_callback)
|
PyObject *buffer_callback)
|
||||||
/*[clinic end generated code: output=706186dba996490c input=5ed6653da99cd97c]*/
|
/*[clinic end generated code: output=706186dba996490c input=b89ce8d0e911fd46]*/
|
||||||
{
|
{
|
||||||
PickleState *state = _Pickle_GetState(module);
|
PickleState *state = _Pickle_GetState(module);
|
||||||
PicklerObject *pickler = _Pickler_New(state);
|
PicklerObject *pickler = _Pickler_New(state);
|
||||||
|
@ -7578,7 +7578,7 @@ Return the pickled representation of the object as a bytes object.
|
||||||
|
|
||||||
The optional *protocol* argument tells the pickler to use the given
|
The optional *protocol* argument tells the pickler to use the given
|
||||||
protocol; supported protocols are 0, 1, 2, 3, 4 and 5. The default
|
protocol; supported protocols are 0, 1, 2, 3, 4 and 5. The default
|
||||||
protocol is 4. It was introduced in Python 3.4, and is incompatible
|
protocol is 5. It was introduced in Python 3.8, and is incompatible
|
||||||
with previous versions.
|
with previous versions.
|
||||||
|
|
||||||
Specifying a negative protocol version selects the highest protocol
|
Specifying a negative protocol version selects the highest protocol
|
||||||
|
@ -7598,7 +7598,7 @@ into *file* as part of the pickle stream. It is an error if
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_pickle_dumps_impl(PyObject *module, PyObject *obj, PyObject *protocol,
|
_pickle_dumps_impl(PyObject *module, PyObject *obj, PyObject *protocol,
|
||||||
int fix_imports, PyObject *buffer_callback)
|
int fix_imports, PyObject *buffer_callback)
|
||||||
/*[clinic end generated code: output=fbab0093a5580fdf input=e543272436c6f987]*/
|
/*[clinic end generated code: output=fbab0093a5580fdf input=139fc546886c63ac]*/
|
||||||
{
|
{
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
PickleState *state = _Pickle_GetState(module);
|
PickleState *state = _Pickle_GetState(module);
|
||||||
|
|
|
@ -111,7 +111,7 @@ PyDoc_STRVAR(_pickle_Pickler___init____doc__,
|
||||||
"\n"
|
"\n"
|
||||||
"The optional *protocol* argument tells the pickler to use the given\n"
|
"The optional *protocol* argument tells the pickler to use the given\n"
|
||||||
"protocol; supported protocols are 0, 1, 2, 3, 4 and 5. The default\n"
|
"protocol; supported protocols are 0, 1, 2, 3, 4 and 5. The default\n"
|
||||||
"protocol is 4. It was introduced in Python 3.4, and is incompatible\n"
|
"protocol is 5. It was introduced in Python 3.8, and is incompatible\n"
|
||||||
"with previous versions.\n"
|
"with previous versions.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Specifying a negative protocol version selects the highest protocol\n"
|
"Specifying a negative protocol version selects the highest protocol\n"
|
||||||
|
@ -614,7 +614,7 @@ PyDoc_STRVAR(_pickle_dump__doc__,
|
||||||
"\n"
|
"\n"
|
||||||
"The optional *protocol* argument tells the pickler to use the given\n"
|
"The optional *protocol* argument tells the pickler to use the given\n"
|
||||||
"protocol; supported protocols are 0, 1, 2, 3, 4 and 5. The default\n"
|
"protocol; supported protocols are 0, 1, 2, 3, 4 and 5. The default\n"
|
||||||
"protocol is 4. It was introduced in Python 3.4, and is incompatible\n"
|
"protocol is 5. It was introduced in Python 3.8, and is incompatible\n"
|
||||||
"with previous versions.\n"
|
"with previous versions.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Specifying a negative protocol version selects the highest protocol\n"
|
"Specifying a negative protocol version selects the highest protocol\n"
|
||||||
|
@ -724,7 +724,7 @@ PyDoc_STRVAR(_pickle_dumps__doc__,
|
||||||
"\n"
|
"\n"
|
||||||
"The optional *protocol* argument tells the pickler to use the given\n"
|
"The optional *protocol* argument tells the pickler to use the given\n"
|
||||||
"protocol; supported protocols are 0, 1, 2, 3, 4 and 5. The default\n"
|
"protocol; supported protocols are 0, 1, 2, 3, 4 and 5. The default\n"
|
||||||
"protocol is 4. It was introduced in Python 3.4, and is incompatible\n"
|
"protocol is 5. It was introduced in Python 3.8, and is incompatible\n"
|
||||||
"with previous versions.\n"
|
"with previous versions.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Specifying a negative protocol version selects the highest protocol\n"
|
"Specifying a negative protocol version selects the highest protocol\n"
|
||||||
|
@ -1077,4 +1077,4 @@ skip_optional_kwonly:
|
||||||
exit:
|
exit:
|
||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
/*[clinic end generated code: output=c7dd60d20ee4895f input=a9049054013a1b77]*/
|
/*[clinic end generated code: output=a9452cf1219f2e7a input=a9049054013a1b77]*/
|
||||||
|
|
Loading…
Reference in New Issue