@@ -352,7 +352,7 @@ The :mod:`pickle` module exports three classes, :class:`Pickler`,
352352 :func: `copyreg.pickle `. It is a mapping whose keys are classes
353353 and whose values are reduction functions. A reduction function
354354 takes a single argument of the associated class and should
355- conform to the same interface as a :meth: `__reduce__ `
355+ conform to the same interface as a :meth: `~object. __reduce__ `
356356 method.
357357
358358 By default, a pickler object will not have a
@@ -372,7 +372,7 @@ The :mod:`pickle` module exports three classes, :class:`Pickler`,
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
375- should conform to the same interface as a :meth: `__reduce__ ` method, and
375+ should conform to the same interface as a :meth: `~object. __reduce__ ` method, and
376376 can optionally return ``NotImplemented `` to fallback on
377377 :attr: `dispatch_table `-registered reducers to pickle ``obj ``.
378378
@@ -508,7 +508,7 @@ The following types can be pickled:
508508
509509* classes accessible from the top level of a module;
510510
511- * instances of such classes whose the result of calling :meth: `__getstate__ `
511+ * instances of such classes whose the result of calling :meth: `~object. __getstate__ `
512512 is picklable (see section :ref: `pickle-inst ` for details).
513513
514514Attempts to pickle unpicklable objects will raise the :exc: `PicklingError `
@@ -544,7 +544,7 @@ purpose, so you can fix bugs in a class or add methods to the class and still
544544load objects that were created with an earlier version of the class. If you
545545plan to have long-lived objects that will see many versions of a class, it may
546546be worthwhile to put a version number in the objects so that suitable
547- conversions can be made by the class's :meth: `__setstate__ ` method.
547+ conversions can be made by the class's :meth: `~object. __setstate__ ` method.
548548
549549
550550.. _pickle-inst :
@@ -559,7 +559,7 @@ customize, and control how class instances are pickled and unpickled.
559559
560560In most cases, no additional code is needed to make instances picklable. By
561561default, pickle will retrieve the class and the attributes of an instance via
562- introspection. When a class instance is unpickled, its :meth: `__init__ ` method
562+ introspection. When a class instance is unpickled, its :meth: `~object. __init__ ` method
563563is usually *not * invoked. The default behaviour first creates an uninitialized
564564instance and then restores the saved attributes. The following code shows an
565565implementation of this behaviour::
@@ -650,30 +650,30 @@ methods:
650650
651651
652652Refer to the section :ref: `pickle-state ` for more information about how to use
653- the methods :meth: `__getstate__ ` and :meth: `__setstate__ `.
653+ the methods :meth: `~object. __getstate__ ` and :meth: `~object. __setstate__ `.
654654
655655.. note ::
656656
657- At unpickling time, some methods like :meth: `__getattr__ `,
658- :meth: `__getattribute__ `, or :meth: `__setattr__ ` may be called upon the
657+ At unpickling time, some methods like :meth: `~object. __getattr__ `,
658+ :meth: `~object. __getattribute__ `, or :meth: `~object. __setattr__ ` may be called upon the
659659 instance. In case those methods rely on some internal invariant being
660- true, the type should implement :meth: `__new__ ` to establish such an
661- invariant, as :meth: `__init__ ` is not called when unpickling an
660+ true, the type should implement :meth: `~object. __new__ ` to establish such an
661+ invariant, as :meth: `~object. __init__ ` is not called when unpickling an
662662 instance.
663663
664664.. index :: pair: copy; protocol
665665
666666As we shall see, pickle does not use directly the methods described above. In
667667fact, these methods are part of the copy protocol which implements the
668- :meth: `__reduce__ ` special method. The copy protocol provides a unified
668+ :meth: `~object. __reduce__ ` special method. The copy protocol provides a unified
669669interface for retrieving the data necessary for pickling and copying
670670objects. [# ]_
671671
672- Although powerful, implementing :meth: `__reduce__ ` directly in your classes is
672+ Although powerful, implementing :meth: `~object. __reduce__ ` directly in your classes is
673673error prone. For this reason, class designers should use the high-level
674- interface (i.e., :meth: `__getnewargs_ex__ `, :meth: `__getstate__ ` and
675- :meth: `__setstate__ `) whenever possible. We will show, however, cases where
676- using :meth: `__reduce__ ` is the only option or leads to more efficient pickling
674+ interface (i.e., :meth: `~object. __getnewargs_ex__ `, :meth: `~object. __getstate__ ` and
675+ :meth: `~object. __setstate__ `) whenever possible. We will show, however, cases where
676+ using :meth: `! __reduce__ ` is the only option or leads to more efficient pickling
677677or both.
678678
679679.. method :: object.__reduce__()
@@ -708,8 +708,9 @@ or both.
708708 These items will be appended to the object either using
709709 ``obj.append(item) `` or, in batch, using ``obj.extend(list_of_items) ``.
710710 This is primarily used for list subclasses, but may be used by other
711- classes as long as they have :meth: `append ` and :meth: `extend ` methods with
712- the appropriate signature. (Whether :meth: `append ` or :meth: `extend ` is
711+ classes as long as they have
712+ :ref: `append and extend methods <typesseq-common >` with
713+ the appropriate signature. (Whether :meth: `!append ` or :meth: `!extend ` is
713714 used depends on which pickle protocol version is used as well as the number
714715 of items to append, so both must be supported.)
715716
@@ -785,8 +786,8 @@ any other code which depends on pickling, then one can create a
785786pickler with a private dispatch table.
786787
787788The global dispatch table managed by the :mod: `copyreg ` module is
788- available as :data: `copyreg.dispatch_table `. Therefore, one may
789- choose to use a modified copy of :data: `copyreg.dispatch_table ` as a
789+ available as :data: `! copyreg.dispatch_table `. Therefore, one may
790+ choose to use a modified copy of :data: `! copyreg.dispatch_table ` as a
790791private dispatch table.
791792
792793For example ::
@@ -825,12 +826,12 @@ Handling Stateful Objects
825826 single: __setstate__() (copy protocol)
826827
827828Here's an example that shows how to modify pickling behavior for a class.
828- The :class: `TextReader ` class opens a text file, and returns the line number and
829+ The :class: `! TextReader ` class below opens a text file, and returns the line number and
829830line contents each time its :meth: `!readline ` method is called. If a
830- :class: `TextReader ` instance is pickled, all attributes *except * the file object
831+ :class: `! TextReader ` instance is pickled, all attributes *except * the file object
831832member are saved. When the instance is unpickled, the file is reopened, and
832- reading resumes from the last location. The :meth: `__setstate__ ` and
833- :meth: `__getstate__ ` methods are used to implement this behavior. ::
833+ reading resumes from the last location. The :meth: `! __setstate__ ` and
834+ :meth: `! __getstate__ ` methods are used to implement this behavior. ::
834835
835836 class TextReader:
836837 """Print and number lines in a text file."""
@@ -895,7 +896,7 @@ functions and classes.
895896
896897For those cases, it is possible to subclass from the :class: `Pickler ` class and
897898implement a :meth: `~Pickler.reducer_override ` method. This method can return an
898- arbitrary reduction tuple (see :meth: `__reduce__ `). It can alternatively return
899+ arbitrary reduction tuple (see :meth: `~object. __reduce__ `). It can alternatively return
899900``NotImplemented `` to fallback to the traditional behavior.
900901
901902If both the :attr: `~Pickler.dispatch_table ` and
@@ -963,7 +964,7 @@ provided by pickle protocol 5 and higher.
963964Provider API
964965^^^^^^^^^^^^
965966
966- The large data objects to be pickled must implement a :meth: `__reduce_ex__ `
967+ The large data objects to be pickled must implement a :meth: `~object. __reduce_ex__ `
967968method specialized for protocol 5 and higher, which returns a
968969:class: `PickleBuffer ` instance (instead of e.g. a :class: `bytes ` object)
969970for any large data.
0 commit comments