Skip to content

Commit 51b5b91

Browse files
committed
boil: test_iter drops its refcount and finalizer-timing checks
Deleted: - test_ref_counting_behavior: __del__ ran as soon as `del x` dropped the last reference, and right after a failed unpack released the iterator. Adapted test_seq_class_reentrant_exhaustion (pythongh-156310): - removed the getrefcount checks that the sequence was not released twice; - removed the second half, where IndexError.__del__ re-entered next() at the moment the exception's last reference went. The re-entrant next() from inside __getitem__ and the revival check stay: they exercise iterator state, not reference counts.
1 parent 86e0e34 commit 51b5b91

1 file changed

Lines changed: 3 additions & 53 deletions

File tree

‎Lib/test/test_iter.py‎

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,10 @@ def test_mutating_seq_class_exhausted_iter(self):
250250
self.assertEqual(list(empit), [5, 6])
251251
self.assertEqual(list(a), [0, 1, 2, 3, 4, 5, 6])
252252

253-
@support.refcount_test
254253
def test_seq_class_reentrant_exhaustion(self):
255-
# gh-156310: a re-entrant next() from inside __getitem__ (or from
256-
# __del__ of the IndexError instance) that exhausts the iterator
257-
# used to make the outer next() DECREF the sequence a second time.
254+
# gh-156310: a re-entrant next() from inside __getitem__ that
255+
# exhausts the iterator used to make the outer next() release the
256+
# sequence a second time.
258257
it = None
259258

260259
class ReentrantGetItem:
@@ -269,31 +268,8 @@ def __getitem__(self, i):
269268
raise IndexError(i)
270269

271270
seq = ReentrantGetItem()
272-
refcount = sys.getrefcount(seq)
273271
it = iter(seq)
274272
self.assertEqual(list(it), [])
275-
del it
276-
support.gc_collect()
277-
self.assertEqual(sys.getrefcount(seq), refcount)
278-
279-
class ReentrantIndexError(IndexError):
280-
def __del__(self):
281-
try:
282-
next(it)
283-
except StopIteration:
284-
pass
285-
286-
class RaiseReentrant:
287-
def __getitem__(self, i):
288-
raise ReentrantIndexError(i)
289-
290-
seq = RaiseReentrant()
291-
refcount = sys.getrefcount(seq)
292-
it = iter(seq)
293-
self.assertEqual(list(it), [])
294-
del it
295-
support.gc_collect()
296-
self.assertEqual(sys.getrefcount(seq), refcount)
297273

298274
# An outer __getitem__ that succeeds after a re-entrant next()
299275
# exhausted the iterator must not revive it.
@@ -1145,32 +1121,6 @@ def test_unpack_iter(self):
11451121
self.assertEqual((a, b, c), (0, 1, 42))
11461122

11471123

1148-
@cpython_only
1149-
@support.requires_refcounting
1150-
def test_ref_counting_behavior(self):
1151-
class C(object):
1152-
count = 0
1153-
def __new__(cls):
1154-
cls.count += 1
1155-
return object.__new__(cls)
1156-
def __del__(self):
1157-
cls = self.__class__
1158-
assert cls.count > 0
1159-
cls.count -= 1
1160-
x = C()
1161-
self.assertEqual(C.count, 1)
1162-
del x
1163-
self.assertEqual(C.count, 0)
1164-
l = [C(), C(), C()]
1165-
self.assertEqual(C.count, 3)
1166-
try:
1167-
a, b = iter(l)
1168-
except ValueError:
1169-
pass
1170-
del l
1171-
self.assertEqual(C.count, 0)
1172-
1173-
11741124
# Make sure StopIteration is a "sink state".
11751125
# This tests various things that weren't sink states in Python 2.2.1,
11761126
# plus various things that always were fine.

0 commit comments

Comments
 (0)