[2.7] bpo-32137: The repr of deeply nested dict now raises a RuntimeError (GH-4570) (#5493)

instead of crashing due to a stack overflow.

This perhaps will fix similar problems in other extension types.
(cherry picked from commit 1fb72d2ad243c965d4432b4e93884064001a2607)
diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py
index 6b2db34..aacd473 100644
--- a/Lib/test/test_dict.py
+++ b/Lib/test/test_dict.py
@@ -3,6 +3,7 @@
 
 import UserDict, random, string
 import gc, weakref
+import sys
 
 
 class DictTest(unittest.TestCase):
@@ -422,6 +423,12 @@
         d = {1: BadRepr()}
         self.assertRaises(Exc, repr, d)
 
+    def test_repr_deep(self):
+        d = {}
+        for i in range(sys.getrecursionlimit() + 100):
+            d = {1: d}
+        self.assertRaises(RuntimeError, repr, d)
+
     def test_le(self):
         self.assertFalse({} < {})
         self.assertFalse({1: 2} < {1L: 2L})