summaryrefslogtreecommitdiffstats
path: root/Doc/whatsnew
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2011-01-23 21:05:46 (GMT)
committerRaymond Hettinger <python@rcn.com>2011-01-23 21:05:46 (GMT)
commit98b140c19620eae8e6e44d9edc7ab02aaeaa4031 (patch)
tree2021953fb225ddeab59694816cf8ce7aee142cb1 /Doc/whatsnew
parente6d4c5bab8d18e32bba6482da1b603b35f2fe254 (diff)
downloadcpython-98b140c19620eae8e6e44d9edc7ab02aaeaa4031.zip
cpython-98b140c19620eae8e6e44d9edc7ab02aaeaa4031.tar.gz
cpython-98b140c19620eae8e6e44d9edc7ab02aaeaa4031.tar.bz2
Add entry for reprlib.
Diffstat (limited to 'Doc/whatsnew')
-rw-r--r--Doc/whatsnew/3.2.rst29
1 files changed, 26 insertions, 3 deletions
diff --git a/Doc/whatsnew/3.2.rst b/Doc/whatsnew/3.2.rst
index 3c1da9f..c680d31 100644
--- a/Doc/whatsnew/3.2.rst
+++ b/Doc/whatsnew/3.2.rst
@@ -987,6 +987,32 @@ implemented::
(Patch submitted by Daniel Urban; :issue:`5867`.)
+reprlib
+-------
+
+When writing a :meth:`__repr__` method for a custom container, it is easy to
+forget to handle the case where a member refers back to the container itself.
+Python's builtin objects such as :class:`list` and :class:`set` handle
+self-reference by displaying "..." in the recursive part of the representation
+string.
+
+To help write such :meth:`__repr__` methods, the :mod:`reprlib` module has a new
+decorator, :func:`reprlib.recursive_repr`, for detecting recursive calls to
+:meth:`__repr__` and substituting a placeholder string instead:
+
+ >>> class MyList(list):
+ @recursive_repr()
+ def __repr__(self):
+ return '<' + '|'.join(map(repr, self)) + '>'
+
+ >>> m = MyList('abc')
+ >>> m.append(m)
+ >>> m.append('x')
+ >>> print(m)
+ <'a'|'b'|'c'|...|'x'>
+
+(Contributed by Raymond Hettinger.)
+
contextlib
----------
@@ -1697,9 +1723,6 @@ reading directly from dictionaries and strings.
- non-UTF8 percent encoding of non-ASCII characters
Issue 2987 for IPv6 (RFC2732) support in urlparse
-.. XXX reprlib.recursive_repr
-
-
Multi-threading
===============