Skip to content

Commit 3870d19

Browse files
authored
gh-101100: Fix Sphinx nitpicks in library/reprlib.rst (#112811)
1 parent e9707d3 commit 3870d19

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

Diff for: Doc/library/reprlib.rst

+30-22
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

@@ -58,29 +58,31 @@ This module provides a class, an instance, and a function:
5858
limits on most sizes.
5959

6060
In addition to size-limiting tools, the module also provides a decorator for
61-
detecting recursive calls to :meth:`__repr__` and substituting a placeholder
62-
string instead.
61+
detecting recursive calls to :meth:`~object.__repr__` and substituting a
62+
placeholder string instead.
6363

6464

6565
.. index:: single: ...; placeholder
6666

6767
.. decorator:: recursive_repr(fillvalue="...")
6868

69-
Decorator for :meth:`__repr__` methods to detect recursive calls within the
69+
Decorator for :meth:`~object.__repr__` methods to detect recursive calls within the
7070
same thread. If a recursive call is made, the *fillvalue* is returned,
71-
otherwise, the usual :meth:`__repr__` call is made. For example:
72-
73-
>>> from reprlib import recursive_repr
74-
>>> class MyList(list):
75-
... @recursive_repr()
76-
... def __repr__(self):
77-
... return '<' + '|'.join(map(repr, self)) + '>'
78-
...
79-
>>> m = MyList('abc')
80-
>>> m.append(m)
81-
>>> m.append('x')
82-
>>> print(m)
83-
<'a'|'b'|'c'|...|'x'>
71+
otherwise, the usual :meth:`!__repr__` call is made. For example:
72+
73+
.. doctest::
74+
75+
>>> from reprlib import recursive_repr
76+
>>> class MyList(list):
77+
... @recursive_repr()
78+
... def __repr__(self):
79+
... return '<' + '|'.join(map(repr, self)) + '>'
80+
...
81+
>>> m = MyList('abc')
82+
>>> m.append(m)
83+
>>> m.append('x')
84+
>>> print(m)
85+
<'a'|'b'|'c'|...|'x'>
8486

8587
.. versionadded:: 3.2
8688

@@ -148,10 +150,10 @@ which format specific object types.
148150
with no line breaks or indentation, like the standard :func:`repr`.
149151
For example:
150152

151-
.. code-block:: pycon
153+
.. doctest:: indent
152154

153155
>>> example = [
154-
1, 'spam', {'a': 2, 'b': 'spam eggs', 'c': {3: 4.5, 6: []}}, 'ham']
156+
... 1, 'spam', {'a': 2, 'b': 'spam eggs', 'c': {3: 4.5, 6: []}}, 'ham']
155157
>>> import reprlib
156158
>>> aRepr = reprlib.Repr()
157159
>>> print(aRepr.repr(example))
@@ -160,7 +162,7 @@ which format specific object types.
160162
If :attr:`~Repr.indent` is set to a string, each recursion level
161163
is placed on its own line, indented by that string:
162164

163-
.. code-block:: pycon
165+
.. doctest:: indent
164166

165167
>>> aRepr.indent = '-->'
166168
>>> print(aRepr.repr(example))
@@ -181,7 +183,7 @@ which format specific object types.
181183
Setting :attr:`~Repr.indent` to a positive integer value behaves as if it
182184
was set to a string with that number of spaces:
183185

184-
.. code-block:: pycon
186+
.. doctest:: indent
185187

186188
>>> aRepr.indent = 4
187189
>>> print(aRepr.repr(example))
@@ -234,7 +236,9 @@ Subclassing Repr Objects
234236
The use of dynamic dispatching by :meth:`Repr.repr1` allows subclasses of
235237
:class:`Repr` to add support for additional built-in object types or to modify
236238
the handling of types already supported. This example shows how special support
237-
for file objects could be added::
239+
for file objects could be added:
240+
241+
.. testcode::
238242

239243
import reprlib
240244
import sys
@@ -248,3 +252,7 @@ for file objects could be added::
248252

249253
aRepr = MyRepr()
250254
print(aRepr.repr(sys.stdin)) # prints '<stdin>'
255+
256+
.. testoutput::
257+
258+
<stdin>

Diff for: Doc/tools/.nitignore

-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ Doc/library/pydoc.rst
8484
Doc/library/pyexpat.rst
8585
Doc/library/random.rst
8686
Doc/library/readline.rst
87-
Doc/library/reprlib.rst
8887
Doc/library/resource.rst
8988
Doc/library/rlcompleter.rst
9089
Doc/library/select.rst

0 commit comments

Comments
 (0)