mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
gh-132713: Fix repr(list) race condition (#132801)
Hold a strong reference to the item while calling repr(item).
This commit is contained in:
parent
722c501dba
commit
a4ea80d523
3 changed files with 26 additions and 1 deletions
|
@ -118,6 +118,19 @@ class ListTest(list_tests.CommonTest):
|
|||
with self.assertRaises((MemoryError, OverflowError)):
|
||||
lst *= size
|
||||
|
||||
def test_repr_mutate(self):
|
||||
class Obj:
|
||||
@staticmethod
|
||||
def __repr__():
|
||||
try:
|
||||
mylist.pop()
|
||||
except IndexError:
|
||||
pass
|
||||
return 'obj'
|
||||
|
||||
mylist = [Obj() for _ in range(5)]
|
||||
self.assertEqual(repr(mylist), '[obj, obj, obj]')
|
||||
|
||||
def test_repr_large(self):
|
||||
# Check the repr of large list objects
|
||||
def check(n):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue