@@ -147,7 +147,7 @@ to read the pickle produced.
147147 earlier versions of Python.
148148
149149* Protocol version 2 was introduced in Python 2.3. It provides much more
150- efficient pickling of :term: `new-style class ` \e s . Refer to :pep: `307 ` for
150+ efficient pickling of :term: `new-style classes <new-style class> ` . Refer to :pep: `307 ` for
151151 information about improvements brought by protocol 2.
152152
153153* Protocol version 3 was added in Python 3.0. It has explicit support for
@@ -261,7 +261,7 @@ process more convenient:
261261 protocol argument is needed. Bytes past the pickled representation
262262 of the object are ignored.
263263
264- Arguments *file *, * fix_imports *, *encoding *, *errors *, *strict * and *buffers *
264+ Arguments *fix_imports *, *encoding *, *errors *, *strict * and *buffers *
265265 have the same meaning as in the :class: `Unpickler ` constructor.
266266
267267 .. versionchanged :: 3.8
@@ -368,7 +368,7 @@ The :mod:`pickle` module exports three classes, :class:`Pickler`,
368368
369369 .. versionadded :: 3.3
370370
371- .. method :: reducer_override(self, obj)
371+ .. method :: reducer_override(obj)
372372
373373 Special reducer that can be defined in :class: `Pickler ` subclasses. This
374374 method has priority over any reducer in the :attr: `dispatch_table `. It
@@ -494,20 +494,18 @@ What can be pickled and unpickled?
494494
495495The following types can be pickled:
496496
497- * ``None ``, ``True ``, and ``False ``
498-
499- * integers, floating point numbers, complex numbers
497+ * ``None ``, ``True ``, and ``False ``;
500498
501- * strings, bytes, bytearrays
499+ * integers, floating-point numbers, complex numbers;
502500
503- * tuples, lists, sets, and dictionaries containing only picklable objects
501+ * strings, bytes, bytearrays;
504502
505- * functions defined at the top level of a module (using :keyword: `def `, not
506- :keyword: `lambda `)
503+ * tuples, lists, sets, and dictionaries containing only picklable objects;
507504
508- * built-in functions defined at the top level of a module
505+ * functions (built-in and user-defined) defined at the top level of a module
506+ (using :keyword: `def `, not :keyword: `lambda `);
509507
510- * classes that are defined at the top level of a module
508+ * classes defined at the top level of a module;
511509
512510* instances of such classes whose the result of calling :meth: `__getstate__ `
513511 is picklable (see section :ref: `pickle-inst ` for details).
@@ -519,14 +517,14 @@ structure may exceed the maximum recursion depth, a :exc:`RecursionError` will b
519517raised in this case. You can carefully raise this limit with
520518:func: `sys.setrecursionlimit `.
521519
522- Note that functions (built-in and user-defined) are pickled by " fully qualified"
523- name reference , not by value. [# ]_ This means that only the function name is
520+ Note that functions (built-in and user-defined) are pickled by fully qualified
521+ name, not by value. [# ]_ This means that only the function name is
524522pickled, along with the name of the module the function is defined in. Neither
525523the function's code, nor any of its function attributes are pickled. Thus the
526524defining module must be importable in the unpickling environment, and the module
527525must contain the named object, otherwise an exception will be raised. [# ]_
528526
529- Similarly, classes are pickled by named reference , so the same restrictions in
527+ Similarly, classes are pickled by fully qualified name , so the same restrictions in
530528the unpickling environment apply. Note that none of the class's code or data is
531529pickled, so in the following example the class attribute ``attr `` is not
532530restored in the unpickling environment::
@@ -536,7 +534,7 @@ restored in the unpickling environment::
536534
537535 picklestring = pickle.dumps(Foo)
538536
539- These restrictions are why picklable functions and classes must be defined in
537+ These restrictions are why picklable functions and classes must be defined at
540538the top level of a module.
541539
542540Similarly, when class instances are pickled, their class's code and data are not
@@ -568,7 +566,7 @@ implementation of this behaviour::
568566 def save(obj):
569567 return (obj.__class__, obj.__dict__)
570568
571- def load (cls, attributes):
569+ def restore (cls, attributes):
572570 obj = cls.__new__(cls)
573571 obj.__dict__.update(attributes)
574572 return obj
@@ -807,14 +805,15 @@ the code ::
807805 f = io.BytesIO()
808806 p = MyPickler(f)
809807
810- does the same, but all instances of ``MyPickler `` will by default
811- share the same dispatch table. The equivalent code using the
812- :mod: `copyreg ` module is ::
808+ does the same but all instances of ``MyPickler `` will by default
809+ share the private dispatch table. On the other hand, the code ::
813810
814811 copyreg.pickle(SomeClass, reduce_SomeClass)
815812 f = io.BytesIO()
816813 p = pickle.Pickler(f)
817814
815+ modifies the global dispatch table shared by all users of the :mod: `copyreg ` module.
816+
818817.. _pickle-state :
819818
820819Handling Stateful Objects
@@ -1117,7 +1116,7 @@ Here is an example of an unpickler allowing only few safe classes from the
11171116 """Helper function analogous to pickle.loads()."""
11181117 return RestrictedUnpickler(io.BytesIO(s)).load()
11191118
1120- A sample usage of our unpickler working has intended::
1119+ A sample usage of our unpickler working as intended::
11211120
11221121 >>> restricted_loads(pickle.dumps([1, 2, range(15)]))
11231122 [1, 2, range(0, 15)]
@@ -1161,7 +1160,7 @@ For the simplest code, use the :func:`dump` and :func:`load` functions. ::
11611160
11621161 # An arbitrary collection of objects supported by pickle.
11631162 data = {
1164- 'a': [1, 2.0, 3, 4+6j ],
1163+ 'a': [1, 2.0, 3+4j ],
11651164 'b': ("character string", b"byte string"),
11661165 'c': {None, True, False}
11671166 }
@@ -1217,6 +1216,6 @@ The following example reads the resulting pickled data. ::
12171216 operations.
12181217
12191218 .. [# ] The limitation on alphanumeric characters is due to the fact
1220- the persistent IDs, in protocol 0, are delimited by the newline
1219+ that persistent IDs in protocol 0 are delimited by the newline
12211220 character. Therefore if any kind of newline characters occurs in
1222- persistent IDs, the resulting pickle will become unreadable.
1221+ persistent IDs, the resulting pickled data will become unreadable.
0 commit comments