summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorandrei kulakov <andrei.avk@gmail.com>2022-05-10 17:22:36 (GMT)
committerGitHub <noreply@github.com>2022-05-10 17:22:36 (GMT)
commit392fd272cde0542859063ea01980091945029e95 (patch)
tree5d27502fde643c3bfa18a8fb32c00d571dbe688c /Doc
parent549567c6e70da4846c105a18a1a89e7dd09680d7 (diff)
downloadcpython-392fd272cde0542859063ea01980091945029e95.zip
cpython-392fd272cde0542859063ea01980091945029e95.tar.gz
cpython-392fd272cde0542859063ea01980091945029e95.tar.bz2
bpo-42259: clarify pprint saferepr docs (#30256)
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/pprint.rst14
1 files changed, 9 insertions, 5 deletions
diff --git a/Doc/library/pprint.rst b/Doc/library/pprint.rst
index 3da5aa9..4e29192 100644
--- a/Doc/library/pprint.rst
+++ b/Doc/library/pprint.rst
@@ -171,17 +171,21 @@ The :mod:`pprint` module defines one class:
.. function:: isrecursive(object)
- Determine if *object* requires a recursive representation.
+ Determine if *object* requires a recursive representation. This function is
+ subject to the same limitations as noted in :func:`saferepr` below and may raise an
+ :exc:`RecursionError` if it fails to detect a recursive object.
One more support function is also defined:
.. function:: saferepr(object)
- Return a string representation of *object*, protected against recursive data
- structures. If the representation of *object* exposes a recursive entry, the
- recursive reference will be represented as ``<Recursion on typename with
- id=number>``. The representation is not otherwise formatted.
+ Return a string representation of *object*, protected against recursion in
+ some common data structures, namely instances of :class:`dict`, :class:`list`
+ and :class:`tuple` or subclasses whose ``__repr__`` has not been overridden. If the
+ representation of object exposes a recursive entry, the recursive reference
+ will be represented as ``<Recursion on typename with id=number>``. The
+ representation is not otherwise formatted.
>>> pprint.saferepr(stuff)
"[<Recursion on list with id=...>, 'spam', 'eggs', 'lumberjack', 'knights', 'ni']"