Skip to content

Commit a9494f6

Browse files
committed
Some nits in the pickle docs.
1 parent cc6c673 commit a9494f6

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

Doc/library/pickle.rst

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -85,45 +85,48 @@ Data stream format
8585
------------------
8686

8787
.. index::
88-
single: XDR
8988
single: External Data Representation
9089

9190
The data format used by :mod:`pickle` is Python-specific. This has the
9291
advantage that there are no restrictions imposed by external standards such as
93-
XDR (which can't represent pointer sharing); however it means that non-Python
94-
programs may not be able to reconstruct pickled Python objects.
92+
JSON or XDR (which can't represent pointer sharing); however it means that
93+
non-Python programs may not be able to reconstruct pickled Python objects.
94+
95+
By default, the :mod:`pickle` data format uses a relatively compact binary
96+
representation. If you need optimal size characteristics, you can efficiently
97+
:doc:`compress <archiving>` pickled data.
9598

96-
By default, the :mod:`pickle` data format uses a compact binary representation.
9799
The module :mod:`pickletools` contains tools for analyzing data streams
98-
generated by :mod:`pickle`.
100+
generated by :mod:`pickle`. :mod:`pickletools` source code has extensive
101+
comments about opcodes used by pickle protocols.
99102

100103
There are currently 4 different protocols which can be used for pickling.
101104

102-
* Protocol version 0 is the original human-readable protocol and is
105+
* Protocol version 0 is the original "human-readable" protocol and is
103106
backwards compatible with earlier versions of Python.
104107

105-
* Protocol version 1 is the old binary format which is also compatible with
108+
* Protocol version 1 is an old binary format which is also compatible with
106109
earlier versions of Python.
107110

108111
* Protocol version 2 was introduced in Python 2.3. It provides much more
109-
efficient pickling of :term:`new-style class`\es.
112+
efficient pickling of :term:`new-style class`\es. Refer to :pep:`307` for
113+
information about improvements brought by protocol 2.
110114

111-
* Protocol version 3 was added in Python 3.0. It has explicit support for
112-
bytes and cannot be unpickled by Python 2.x pickle modules. This is
113-
the current recommended protocol, use it whenever it is possible.
114-
115-
Refer to :pep:`307` for information about improvements brought by
116-
protocol 2. See :mod:`pickletools`'s source code for extensive
117-
comments about opcodes used by pickle protocols.
115+
* Protocol version 3 was added in Python 3. It has explicit support for
116+
:class:`bytes` objects and cannot be unpickled by Python 2.x. This is
117+
the default as well as the current recommended protocol; use it whenever
118+
possible.
118119

119120

120121
Module Interface
121122
----------------
122123

123-
To serialize an object hierarchy, you first create a pickler, then you call the
124-
pickler's :meth:`dump` method. To de-serialize a data stream, you first create
125-
an unpickler, then you call the unpickler's :meth:`load` method. The
126-
:mod:`pickle` module provides the following constant:
124+
To serialize an object hierarchy, you simply call the :func:`dumps` function.
125+
Similarly, to de-serialize a data stream, you call the :func:`loads` function.
126+
However, if you want more control over serialization and de-serialization,
127+
you can create a :class:`Pickler` or an :class:`Unpickler` object, respectively.
128+
129+
The :mod:`pickle` module provides the following constants:
127130

128131

129132
.. data:: HIGHEST_PROTOCOL
@@ -134,8 +137,7 @@ an unpickler, then you call the unpickler's :meth:`load` method. The
134137
.. data:: DEFAULT_PROTOCOL
135138

136139
The default protocol used for pickling. May be less than HIGHEST_PROTOCOL.
137-
Currently the default protocol is 3; a backward-incompatible protocol
138-
designed for Python 3.0.
140+
Currently the default protocol is 3, a new protocol designed for Python 3.0.
139141

140142

141143
The :mod:`pickle` module provides the following functions to make the pickling

0 commit comments

Comments
 (0)