10
10
11
11
--------------
12
12
13
- The :mod: `reprlib ` module provides a means for producing object representations
13
+ The :mod: `! reprlib ` module provides a means for producing object representations
14
14
with limits on the size of the resulting strings. This is used in the Python
15
15
debugger and may be useful in other contexts as well.
16
16
@@ -39,29 +39,31 @@ This module provides a class, an instance, and a function:
39
39
limits on most sizes.
40
40
41
41
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.
44
44
45
45
46
46
.. index :: single: ...; placeholder
47
47
48
48
.. decorator :: recursive_repr(fillvalue="...")
49
49
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
51
51
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'>
65
67
66
68
.. versionadded :: 3.2
67
69
@@ -155,7 +157,9 @@ Subclassing Repr Objects
155
157
The use of dynamic dispatching by :meth: `Repr.repr1 ` allows subclasses of
156
158
:class: `Repr ` to add support for additional built-in object types or to modify
157
159
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 ::
159
163
160
164
import reprlib
161
165
import sys
@@ -169,3 +173,7 @@ for file objects could be added::
169
173
170
174
aRepr = MyRepr()
171
175
print(aRepr.repr(sys.stdin)) # prints '<stdin>'
176
+
177
+ .. testoutput ::
178
+
179
+ <stdin>
0 commit comments