Skip to content

Commit 1e719d3

Browse files
authored
[3.11] gh-101100: Fix Sphinx nitpicks in library/reprlib.rst (#112811) (#112815)
(cherry-picked from commit 3870d19)
1 parent b49c963 commit 1e719d3

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

Doc/library/reprlib.rst

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
--------------
1212

13-
The :mod:`reprlib` module provides a means for producing object representations
13+
The :mod:`!reprlib` module provides a means for producing object representations
1414
with limits on the size of the resulting strings. This is used in the Python
1515
debugger and may be useful in other contexts as well.
1616

@@ -39,29 +39,31 @@ This module provides a class, an instance, and a function:
3939
limits on most sizes.
4040

4141
In addition to size-limiting tools, the module also provides a decorator for
42-
detecting recursive calls to :meth:`__repr__` and substituting a placeholder
43-
string instead.
42+
detecting recursive calls to :meth:`~object.__repr__` and substituting a
43+
placeholder string instead.
4444

4545

4646
.. index:: single: ...; placeholder
4747

4848
.. decorator:: recursive_repr(fillvalue="...")
4949

50-
Decorator for :meth:`__repr__` methods to detect recursive calls within the
50+
Decorator for :meth:`~object.__repr__` methods to detect recursive calls within the
5151
same thread. If a recursive call is made, the *fillvalue* is returned,
52-
otherwise, the usual :meth:`__repr__` call is made. For example:
53-
54-
>>> from reprlib import recursive_repr
55-
>>> class MyList(list):
56-
... @recursive_repr()
57-
... def __repr__(self):
58-
... return '<' + '|'.join(map(repr, self)) + '>'
59-
...
60-
>>> m = MyList('abc')
61-
>>> m.append(m)
62-
>>> m.append('x')
63-
>>> print(m)
64-
<'a'|'b'|'c'|...|'x'>
52+
otherwise, the usual :meth:`!__repr__` call is made. For example:
53+
54+
.. doctest::
55+
56+
>>> from reprlib import recursive_repr
57+
>>> class MyList(list):
58+
... @recursive_repr()
59+
... def __repr__(self):
60+
... return '<' + '|'.join(map(repr, self)) + '>'
61+
...
62+
>>> m = MyList('abc')
63+
>>> m.append(m)
64+
>>> m.append('x')
65+
>>> print(m)
66+
<'a'|'b'|'c'|...|'x'>
6567

6668
.. versionadded:: 3.2
6769

@@ -155,7 +157,9 @@ Subclassing Repr Objects
155157
The use of dynamic dispatching by :meth:`Repr.repr1` allows subclasses of
156158
:class:`Repr` to add support for additional built-in object types or to modify
157159
the handling of types already supported. This example shows how special support
158-
for file objects could be added::
160+
for file objects could be added:
161+
162+
.. testcode::
159163

160164
import reprlib
161165
import sys
@@ -169,3 +173,7 @@ for file objects could be added::
169173

170174
aRepr = MyRepr()
171175
print(aRepr.repr(sys.stdin)) # prints '<stdin>'
176+
177+
.. testoutput::
178+
179+
<stdin>

Doc/tools/.nitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ Doc/library/pydoc.rst
8787
Doc/library/pyexpat.rst
8888
Doc/library/random.rst
8989
Doc/library/readline.rst
90-
Doc/library/reprlib.rst
9190
Doc/library/resource.rst
9291
Doc/library/rlcompleter.rst
9392
Doc/library/select.rst

0 commit comments

Comments
 (0)