mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Issue #26492: Exhausted iterator of array.array now conforms with the behavior
of iterators of other mutable sequences: it lefts exhausted even if iterated array is extended.
This commit is contained in:
		
							parent
							
								
									f39c0ac62f
								
							
						
					
					
						commit
						ab0d198c7a
					
				
					 3 changed files with 41 additions and 6 deletions
				
			
		|  | @ -318,8 +318,19 @@ def test_iterator_pickle(self): | |||
|             d = pickle.dumps((itorig, orig), proto) | ||||
|             it, a = pickle.loads(d) | ||||
|             a.fromlist(data2) | ||||
|             self.assertEqual(type(it), type(itorig)) | ||||
|             self.assertEqual(list(it), data2) | ||||
|             self.assertEqual(list(it), []) | ||||
| 
 | ||||
|     def test_exhausted_iterator(self): | ||||
|         a = array.array(self.typecode, self.example) | ||||
|         self.assertEqual(list(a), list(self.example)) | ||||
|         exhit = iter(a) | ||||
|         empit = iter(a) | ||||
|         for x in exhit:  # exhaust the iterator | ||||
|             next(empit)  # not exhausted | ||||
|         a.append(self.outside) | ||||
|         self.assertEqual(list(exhit), []) | ||||
|         self.assertEqual(list(empit), [self.outside]) | ||||
|         self.assertEqual(list(a), list(self.example) + [self.outside]) | ||||
| 
 | ||||
|     def test_insert(self): | ||||
|         a = array.array(self.typecode, self.example) | ||||
|  | @ -1070,6 +1081,12 @@ def test_obsolete_write_lock(self): | |||
|         a = array.array('B', b"") | ||||
|         self.assertRaises(BufferError, getbuffer_with_null_view, a) | ||||
| 
 | ||||
|     def test_free_after_iterating(self): | ||||
|         support.check_free_after_iterating(self, iter, array.array, | ||||
|                                            (self.typecode,)) | ||||
|         support.check_free_after_iterating(self, reversed, array.array, | ||||
|                                            (self.typecode,)) | ||||
| 
 | ||||
| class StringTest(BaseTest): | ||||
| 
 | ||||
|     def test_setitem(self): | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Serhiy Storchaka
						Serhiy Storchaka