mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
GH-132554: "Virtual" iterators (GH-132555)
* FOR_ITER now pushes either the iterator and NULL or leaves the iterable and pushes tagged zero * NEXT_ITER uses the tagged int as the index into the sequence or, if TOS is NULL, iterates as before.
This commit is contained in:
parent
9300a596d3
commit
f6f4e8a662
25 changed files with 713 additions and 618 deletions
|
@ -365,5 +365,20 @@ class ListTest(list_tests.CommonTest):
|
|||
rc, _, _ = assert_python_ok("-c", code)
|
||||
self.assertEqual(rc, 0)
|
||||
|
||||
def test_list_overwrite_local(self):
|
||||
"""Test that overwriting the last reference to the
|
||||
iterable doesn't prematurely free the iterable"""
|
||||
|
||||
def foo(x):
|
||||
self.assertEqual(sys.getrefcount(x), 1)
|
||||
r = 0
|
||||
for i in x:
|
||||
r += i
|
||||
x = None
|
||||
return r
|
||||
|
||||
self.assertEqual(foo(list(range(10))), 45)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue