mirror of
				https://github.com/graphql-python/graphene.git
				synced 2025-10-31 07:57:26 +03:00 
			
		
		
		
	Fix enum value equality comparison
This commit is contained in:
		
							parent
							
								
									baaef0d21a
								
							
						
					
					
						commit
						fcbb04eeb1
					
				|  | @ -9,7 +9,10 @@ from .unmountedtype import UnmountedType | |||
| def eq_enum(self, other): | ||||
|     if isinstance(other, self.__class__): | ||||
|         return self is other | ||||
|     return self.value is other | ||||
|     if isinstance(other, PyEnum): | ||||
|         # Identical values from different Enum classes are not equal. | ||||
|         return False | ||||
|     return self.value == other | ||||
| 
 | ||||
| 
 | ||||
| def hash_enum(self): | ||||
|  |  | |||
|  | @ -230,6 +230,25 @@ def test_enum_to_enum_comparison_should_differ(): | |||
|     assert RGB1.BLUE != RGB2.BLUE | ||||
| 
 | ||||
| 
 | ||||
| def test_enum_to_value_comparison(): | ||||
|     class RGB(Enum): | ||||
|         RED = "red" | ||||
|         GREEN = "green" | ||||
|         BLUE = "blue" | ||||
| 
 | ||||
|     assert "red" == RGB.RED | ||||
|     assert "red" != RGB.GREEN | ||||
|     assert "red" != RGB.BLUE | ||||
| 
 | ||||
|     assert "green" != RGB.RED | ||||
|     assert "green" == RGB.GREEN | ||||
|     assert "green" != RGB.BLUE | ||||
| 
 | ||||
|     assert "blue" != RGB.RED | ||||
|     assert "blue" != RGB.GREEN | ||||
|     assert "blue" == RGB.BLUE | ||||
| 
 | ||||
| 
 | ||||
| def test_enum_skip_meta_from_members(): | ||||
|     class RGB1(Enum): | ||||
|         class Meta: | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user