summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_defaultdict.py
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-02-08 01:05:21 (GMT)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-02-08 01:05:21 (GMT)
commit3e5f8a6975cb7f7c3dc9f84686f27c49bc4aa75a (patch)
treeea8428d58e9dc2798ad2374042caea5ee9bee6d4 /Lib/test/test_defaultdict.py
parentec4301e60f8380d696115b598fea88cea239947c (diff)
downloadcpython-3e5f8a6975cb7f7c3dc9f84686f27c49bc4aa75a.zip
cpython-3e5f8a6975cb7f7c3dc9f84686f27c49bc4aa75a.tar.gz
cpython-3e5f8a6975cb7f7c3dc9f84686f27c49bc4aa75a.tar.bz2
issue 2045: Infinite recursion when printing a subclass of defaultdict,
if default_factory is set to a bound method. Backport of r60663.
Diffstat (limited to 'Lib/test/test_defaultdict.py')
-rw-r--r--Lib/test/test_defaultdict.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_defaultdict.py b/Lib/test/test_defaultdict.py
index 08be005..5724fd0 100644
--- a/Lib/test/test_defaultdict.py
+++ b/Lib/test/test_defaultdict.py
@@ -141,6 +141,29 @@ class TestDefaultDict(unittest.TestCase):
else:
self.fail("expected KeyError")
+ def test_recursive_repr(self):
+ # Issue2045: stack overflow when default_factory is a bound method
+ class sub(defaultdict):
+ def __init__(self):
+ self.default_factory = self._factory
+ def _factory(self):
+ return []
+ d = sub()
+ self.assert_(repr(d).startswith(
+ "defaultdict(<bound method sub._factory of defaultdict(..."))
+
+ # NOTE: printing a subclass of a builtin type does not call its
+ # tp_print slot. So this part is essentially the same test as above.
+ tfn = tempfile.mktemp()
+ try:
+ f = open(tfn, "w+")
+ try:
+ print >>f, d
+ finally:
+ f.close()
+ finally:
+ os.remove(tfn)
+
def test_main():
test_support.run_unittest(TestDefaultDict)