summaryrefslogtreecommitdiffstats
path: root/Lib/collections.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2010-09-13 21:36:00 (GMT)
committerRaymond Hettinger <python@rcn.com>2010-09-13 21:36:00 (GMT)
commit98a5f3f83883a6c924cfa1360647dcbf3152ea10 (patch)
treeb4cebb01dd9237c72656b942aa34406dc6fed5a0 /Lib/collections.py
parent9f0cbf1c727f7de884c392176ab4f19a49924c9b (diff)
downloadcpython-98a5f3f83883a6c924cfa1360647dcbf3152ea10.zip
cpython-98a5f3f83883a6c924cfa1360647dcbf3152ea10.tar.gz
cpython-98a5f3f83883a6c924cfa1360647dcbf3152ea10.tar.bz2
Issue 9840: Add reprlib.recursive_repr(), a decorator for handling recursive calls to __repr__ methods.
Diffstat (limited to 'Lib/collections.py')
-rw-r--r--Lib/collections.py18
1 files changed, 6 insertions, 12 deletions
diff --git a/Lib/collections.py b/Lib/collections.py
index 9120ab6..78b4115 100644
--- a/Lib/collections.py
+++ b/Lib/collections.py
@@ -13,6 +13,7 @@ import sys as _sys
import heapq as _heapq
from weakref import proxy as _proxy
from itertools import repeat as _repeat, chain as _chain, starmap as _starmap
+from reprlib import recursive_repr as _recursive_repr
################################################################################
### OrderedDict
@@ -43,7 +44,6 @@ class OrderedDict(dict, MutableMapping):
'''
if len(args) > 1:
raise TypeError('expected at most 1 arguments, got %d' % len(args))
- self.__in_repr = False # detects recursive repr
try:
self.__root
except AttributeError:
@@ -97,10 +97,10 @@ class OrderedDict(dict, MutableMapping):
def __reduce__(self):
'Return state information for pickling'
items = [[k, self[k]] for k in self]
- tmp = self.__map, self.__root, self.__in_repr
- del self.__map, self.__root, self.__in_repr
+ tmp = self.__map, self.__root
+ del self.__map, self.__root
inst_dict = vars(self).copy()
- self.__map, self.__root, self.__in_repr = tmp
+ self.__map, self.__root = tmp
if inst_dict:
return (self.__class__, (items,), inst_dict)
return self.__class__, (items,)
@@ -167,18 +167,12 @@ class OrderedDict(dict, MutableMapping):
items = MutableMapping.items
__ne__ = MutableMapping.__ne__
+ @_recursive_repr()
def __repr__(self):
'od.__repr__() <==> repr(od)'
if not self:
return '%s()' % (self.__class__.__name__,)
- if self.__in_repr:
- return '...'
- self.__in_repr = True
- try:
- result = '%s(%r)' % (self.__class__.__name__, list(self.items()))
- finally:
- self.__in_repr = False
- return result
+ return '%s(%r)' % (self.__class__.__name__, list(self.items()))
def copy(self):
'od.copy() -> a shallow copy of od'