Skip to content

Commit 392fd27

Browse files
authored
bpo-42259: clarify pprint saferepr docs (#30256)
1 parent 549567c commit 392fd27

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Doc/library/pprint.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,21 @@ The :mod:`pprint` module defines one class:
171171

172172
.. function:: isrecursive(object)
173173

174-
Determine if *object* requires a recursive representation.
174+
Determine if *object* requires a recursive representation. This function is
175+
subject to the same limitations as noted in :func:`saferepr` below and may raise an
176+
:exc:`RecursionError` if it fails to detect a recursive object.
175177

176178

177179
One more support function is also defined:
178180

179181
.. function:: saferepr(object)
180182

181-
Return a string representation of *object*, protected against recursive data
182-
structures. If the representation of *object* exposes a recursive entry, the
183-
recursive reference will be represented as ``<Recursion on typename with
184-
id=number>``. The representation is not otherwise formatted.
183+
Return a string representation of *object*, protected against recursion in
184+
some common data structures, namely instances of :class:`dict`, :class:`list`
185+
and :class:`tuple` or subclasses whose ``__repr__`` has not been overridden. If the
186+
representation of object exposes a recursive entry, the recursive reference
187+
will be represented as ``<Recursion on typename with id=number>``. The
188+
representation is not otherwise formatted.
185189

186190
>>> pprint.saferepr(stuff)
187191
"[<Recursion on list with id=...>, 'spam', 'eggs', 'lumberjack', 'knights', 'ni']"

0 commit comments

Comments
 (0)