Skip to content

Commit ec69e1d

Browse files
gh-101100: Fix dangling references in pickle.rst (#114972)
Co-authored-by: Alex Waygood <[email protected]>
1 parent 848c867 commit ec69e1d

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

Doc/library/pickle.rst

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ The :mod:`pickle` module exports three classes, :class:`Pickler`,
356356
:func:`copyreg.pickle`. It is a mapping whose keys are classes
357357
and whose values are reduction functions. A reduction function
358358
takes a single argument of the associated class and should
359-
conform to the same interface as a :meth:`__reduce__`
359+
conform to the same interface as a :meth:`~object.__reduce__`
360360
method.
361361

362362
By default, a pickler object will not have a
@@ -376,7 +376,7 @@ The :mod:`pickle` module exports three classes, :class:`Pickler`,
376376

377377
Special reducer that can be defined in :class:`Pickler` subclasses. This
378378
method has priority over any reducer in the :attr:`dispatch_table`. It
379-
should conform to the same interface as a :meth:`__reduce__` method, and
379+
should conform to the same interface as a :meth:`~object.__reduce__` method, and
380380
can optionally return ``NotImplemented`` to fallback on
381381
:attr:`dispatch_table`-registered reducers to pickle ``obj``.
382382

@@ -516,7 +516,7 @@ The following types can be pickled:
516516

517517
* classes accessible from the top level of a module;
518518

519-
* instances of such classes whose the result of calling :meth:`__getstate__`
519+
* instances of such classes whose the result of calling :meth:`~object.__getstate__`
520520
is picklable (see section :ref:`pickle-inst` for details).
521521

522522
Attempts to pickle unpicklable objects will raise the :exc:`PicklingError`
@@ -552,7 +552,7 @@ purpose, so you can fix bugs in a class or add methods to the class and still
552552
load objects that were created with an earlier version of the class. If you
553553
plan to have long-lived objects that will see many versions of a class, it may
554554
be worthwhile to put a version number in the objects so that suitable
555-
conversions can be made by the class's :meth:`__setstate__` method.
555+
conversions can be made by the class's :meth:`~object.__setstate__` method.
556556

557557

558558
.. _pickle-inst:
@@ -567,7 +567,7 @@ customize, and control how class instances are pickled and unpickled.
567567

568568
In most cases, no additional code is needed to make instances picklable. By
569569
default, pickle will retrieve the class and the attributes of an instance via
570-
introspection. When a class instance is unpickled, its :meth:`__init__` method
570+
introspection. When a class instance is unpickled, its :meth:`~object.__init__` method
571571
is usually *not* invoked. The default behaviour first creates an uninitialized
572572
instance and then restores the saved attributes. The following code shows an
573573
implementation of this behaviour::
@@ -658,30 +658,30 @@ methods:
658658

659659

660660
Refer to the section :ref:`pickle-state` for more information about how to use
661-
the methods :meth:`__getstate__` and :meth:`__setstate__`.
661+
the methods :meth:`~object.__getstate__` and :meth:`~object.__setstate__`.
662662

663663
.. note::
664664

665-
At unpickling time, some methods like :meth:`__getattr__`,
666-
:meth:`__getattribute__`, or :meth:`__setattr__` may be called upon the
665+
At unpickling time, some methods like :meth:`~object.__getattr__`,
666+
:meth:`~object.__getattribute__`, or :meth:`~object.__setattr__` may be called upon the
667667
instance. In case those methods rely on some internal invariant being
668-
true, the type should implement :meth:`__new__` to establish such an
669-
invariant, as :meth:`__init__` is not called when unpickling an
668+
true, the type should implement :meth:`~object.__new__` to establish such an
669+
invariant, as :meth:`~object.__init__` is not called when unpickling an
670670
instance.
671671

672672
.. index:: pair: copy; protocol
673673

674674
As we shall see, pickle does not use directly the methods described above. In
675675
fact, these methods are part of the copy protocol which implements the
676-
:meth:`__reduce__` special method. The copy protocol provides a unified
676+
:meth:`~object.__reduce__` special method. The copy protocol provides a unified
677677
interface for retrieving the data necessary for pickling and copying
678678
objects. [#]_
679679

680-
Although powerful, implementing :meth:`__reduce__` directly in your classes is
680+
Although powerful, implementing :meth:`~object.__reduce__` directly in your classes is
681681
error prone. For this reason, class designers should use the high-level
682-
interface (i.e., :meth:`__getnewargs_ex__`, :meth:`__getstate__` and
683-
:meth:`__setstate__`) whenever possible. We will show, however, cases where
684-
using :meth:`__reduce__` is the only option or leads to more efficient pickling
682+
interface (i.e., :meth:`~object.__getnewargs_ex__`, :meth:`~object.__getstate__` and
683+
:meth:`~object.__setstate__`) whenever possible. We will show, however, cases where
684+
using :meth:`!__reduce__` is the only option or leads to more efficient pickling
685685
or both.
686686

687687
.. method:: object.__reduce__()
@@ -716,8 +716,9 @@ or both.
716716
These items will be appended to the object either using
717717
``obj.append(item)`` or, in batch, using ``obj.extend(list_of_items)``.
718718
This is primarily used for list subclasses, but may be used by other
719-
classes as long as they have :meth:`append` and :meth:`extend` methods with
720-
the appropriate signature. (Whether :meth:`append` or :meth:`extend` is
719+
classes as long as they have
720+
:ref:`append and extend methods <typesseq-common>` with
721+
the appropriate signature. (Whether :meth:`!append` or :meth:`!extend` is
721722
used depends on which pickle protocol version is used as well as the number
722723
of items to append, so both must be supported.)
723724

@@ -793,8 +794,8 @@ any other code which depends on pickling, then one can create a
793794
pickler with a private dispatch table.
794795

795796
The global dispatch table managed by the :mod:`copyreg` module is
796-
available as :data:`copyreg.dispatch_table`. Therefore, one may
797-
choose to use a modified copy of :data:`copyreg.dispatch_table` as a
797+
available as :data:`!copyreg.dispatch_table`. Therefore, one may
798+
choose to use a modified copy of :data:`!copyreg.dispatch_table` as a
798799
private dispatch table.
799800

800801
For example ::
@@ -833,12 +834,12 @@ Handling Stateful Objects
833834
single: __setstate__() (copy protocol)
834835

835836
Here's an example that shows how to modify pickling behavior for a class.
836-
The :class:`TextReader` class opens a text file, and returns the line number and
837+
The :class:`!TextReader` class below opens a text file, and returns the line number and
837838
line contents each time its :meth:`!readline` method is called. If a
838-
:class:`TextReader` instance is pickled, all attributes *except* the file object
839+
:class:`!TextReader` instance is pickled, all attributes *except* the file object
839840
member are saved. When the instance is unpickled, the file is reopened, and
840-
reading resumes from the last location. The :meth:`__setstate__` and
841-
:meth:`__getstate__` methods are used to implement this behavior. ::
841+
reading resumes from the last location. The :meth:`!__setstate__` and
842+
:meth:`!__getstate__` methods are used to implement this behavior. ::
842843

843844
class TextReader:
844845
"""Print and number lines in a text file."""
@@ -903,7 +904,7 @@ functions and classes.
903904

904905
For those cases, it is possible to subclass from the :class:`Pickler` class and
905906
implement a :meth:`~Pickler.reducer_override` method. This method can return an
906-
arbitrary reduction tuple (see :meth:`__reduce__`). It can alternatively return
907+
arbitrary reduction tuple (see :meth:`~object.__reduce__`). It can alternatively return
907908
``NotImplemented`` to fallback to the traditional behavior.
908909

909910
If both the :attr:`~Pickler.dispatch_table` and
@@ -971,7 +972,7 @@ provided by pickle protocol 5 and higher.
971972
Provider API
972973
^^^^^^^^^^^^
973974

974-
The large data objects to be pickled must implement a :meth:`__reduce_ex__`
975+
The large data objects to be pickled must implement a :meth:`~object.__reduce_ex__`
975976
method specialized for protocol 5 and higher, which returns a
976977
:class:`PickleBuffer` instance (instead of e.g. a :class:`bytes` object)
977978
for any large data.

Doc/tools/.nitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ Doc/library/mmap.rst
4646
Doc/library/multiprocessing.rst
4747
Doc/library/optparse.rst
4848
Doc/library/os.rst
49-
Doc/library/pickle.rst
5049
Doc/library/pickletools.rst
5150
Doc/library/platform.rst
5251
Doc/library/plistlib.rst

0 commit comments

Comments
 (0)