mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	Closes SF bug #628246.
The _update method detected mutable elements by trapping TypeErrors. Unfortunately, this masked useful TypeErrors raised by the iterable itself. For cases where it is possible for an iterable to raise a TypeError, the iterable is pre-converted to a list outside the try/except so that any TypeErrors propagate through.
This commit is contained in:
		
							parent
							
								
									dde800ec4e
								
							
						
					
					
						commit
						1eb1fb814b
					
				
					 2 changed files with 27 additions and 0 deletions
				
			
		|  | @ -320,6 +320,8 @@ def _update(self, iterable): | ||||||
|             return |             return | ||||||
| 
 | 
 | ||||||
|         value = True |         value = True | ||||||
|  |         if type(iterable) not in (list, tuple, dict, file, xrange, str): | ||||||
|  |             iterable = list(iterable) | ||||||
|         it = iter(iterable) |         it = iter(iterable) | ||||||
|         while True: |         while True: | ||||||
|             try: |             try: | ||||||
|  |  | ||||||
|  | @ -132,6 +132,30 @@ def setUp(self): | ||||||
| 
 | 
 | ||||||
| #============================================================================== | #============================================================================== | ||||||
| 
 | 
 | ||||||
|  | def baditer(): | ||||||
|  |     raise TypeError | ||||||
|  |     yield True | ||||||
|  | 
 | ||||||
|  | def gooditer(): | ||||||
|  |     yield True | ||||||
|  | 
 | ||||||
|  | class TestExceptionPropagation(unittest.TestCase): | ||||||
|  |     """SF 628246:  Set constructor should not trap iterator TypeErrors""" | ||||||
|  | 
 | ||||||
|  |     def test_instanceWithException(self): | ||||||
|  |         self.assertRaises(TypeError, Set, baditer()) | ||||||
|  | 
 | ||||||
|  |     def test_instancesWithoutException(self): | ||||||
|  |         """All of these iterables should load without exception.""" | ||||||
|  |         Set([1,2,3]) | ||||||
|  |         Set((1,2,3)) | ||||||
|  |         Set({'one':1, 'two':2, 'three':3}) | ||||||
|  |         Set(xrange(3)) | ||||||
|  |         Set('abc') | ||||||
|  |         Set(gooditer()) | ||||||
|  | 
 | ||||||
|  | #============================================================================== | ||||||
|  | 
 | ||||||
| class TestSetOfSets(unittest.TestCase): | class TestSetOfSets(unittest.TestCase): | ||||||
|     def test_constructor(self): |     def test_constructor(self): | ||||||
|         inner = Set([1]) |         inner = Set([1]) | ||||||
|  | @ -604,6 +628,7 @@ def setUp(self): | ||||||
| def makeAllTests(): | def makeAllTests(): | ||||||
|     suite = unittest.TestSuite() |     suite = unittest.TestSuite() | ||||||
|     for klass in (TestSetOfSets, |     for klass in (TestSetOfSets, | ||||||
|  |                   TestExceptionPropagation, | ||||||
|                   TestBasicOpsEmpty, |                   TestBasicOpsEmpty, | ||||||
|                   TestBasicOpsSingleton, |                   TestBasicOpsSingleton, | ||||||
|                   TestBasicOpsTuple, |                   TestBasicOpsTuple, | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Raymond Hettinger
						Raymond Hettinger