mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
bpo-32137: The repr of deeply nested dict now raises a RecursionError (#4570)
instead of crashing due to a stack overflow. This perhaps will fix similar problems in other extension types.
This commit is contained in:
parent
eea3cc1ef0
commit
1fb72d2ad2
7 changed files with 26 additions and 9 deletions
|
@ -1,6 +1,7 @@
|
|||
# tests common to dict and UserDict
|
||||
import unittest
|
||||
import collections
|
||||
import sys
|
||||
|
||||
|
||||
class BasicTestMappingProtocol(unittest.TestCase):
|
||||
|
@ -619,6 +620,14 @@ class TestHashMappingProtocol(TestMappingProtocol):
|
|||
d = self._full_mapping({1: BadRepr()})
|
||||
self.assertRaises(Exc, repr, d)
|
||||
|
||||
def test_repr_deep(self):
|
||||
d = self._empty_mapping()
|
||||
for i in range(sys.getrecursionlimit() + 100):
|
||||
d0 = d
|
||||
d = self._empty_mapping()
|
||||
d[1] = d0
|
||||
self.assertRaises(RecursionError, repr, d)
|
||||
|
||||
def test_eq(self):
|
||||
self.assertEqual(self._empty_mapping(), self._empty_mapping())
|
||||
self.assertEqual(self._full_mapping({1: 2}),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue