diff --git a/graphene/types/enum.py b/graphene/types/enum.py index d3469a15..37988568 100644 --- a/graphene/types/enum.py +++ b/graphene/types/enum.py @@ -9,7 +9,10 @@ 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): diff --git a/graphene/types/tests/test_enum.py b/graphene/types/tests/test_enum.py index e6fce66c..79f57681 100644 --- a/graphene/types/tests/test_enum.py +++ b/graphene/types/tests/test_enum.py @@ -230,6 +230,25 @@ class RGB2(Enum): 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: