mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	bpo-44342: [Enum] fix data type search (GH-26667)
In an inheritance chain of int -> my_int -> final_int the data type is now final_int (not my_int)
This commit is contained in:
		
							parent
							
								
									e26014f1c4
								
							
						
					
					
						commit
						3a7cccfd6c
					
				
					 2 changed files with 9 additions and 1 deletions
				
			
		|  | @ -818,7 +818,7 @@ def _find_data_type(bases): | ||||||
|                         data_types.add(candidate or base) |                         data_types.add(candidate or base) | ||||||
|                         break |                         break | ||||||
|                     else: |                     else: | ||||||
|                         candidate = base |                         candidate = candidate or base | ||||||
|             if len(data_types) > 1: |             if len(data_types) > 1: | ||||||
|                 raise TypeError('%r: too many data types: %r' % (class_name, data_types)) |                 raise TypeError('%r: too many data types: %r' % (class_name, data_types)) | ||||||
|             elif data_types: |             elif data_types: | ||||||
|  |  | ||||||
|  | @ -658,6 +658,14 @@ class MyEnum(HexInt, enum.Enum): | ||||||
|             def __repr__(self): |             def __repr__(self): | ||||||
|                 return '<%s.%s: %r>' % (self.__class__.__name__, self._name_, self._value_) |                 return '<%s.%s: %r>' % (self.__class__.__name__, self._name_, self._value_) | ||||||
|         self.assertEqual(repr(MyEnum.A), '<MyEnum.A: 0x1>') |         self.assertEqual(repr(MyEnum.A), '<MyEnum.A: 0x1>') | ||||||
|  |         # | ||||||
|  |         class SillyInt(HexInt): | ||||||
|  |             pass | ||||||
|  |         class MyOtherEnum(SillyInt, enum.Enum): | ||||||
|  |             D = 4 | ||||||
|  |             E = 5 | ||||||
|  |             F = 6 | ||||||
|  |         self.assertIs(MyOtherEnum._member_type_, SillyInt) | ||||||
| 
 | 
 | ||||||
|     def test_too_many_data_types(self): |     def test_too_many_data_types(self): | ||||||
|         with self.assertRaisesRegex(TypeError, 'too many data types'): |         with self.assertRaisesRegex(TypeError, 'too many data types'): | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Ethan Furman
						Ethan Furman