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
1414with limits on the size of the resulting strings. This is used in the Python
1515debugger 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
4141In 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
155157The 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
157159the 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>
0 commit comments