From 2594cdb61409f8ecedf0958ee959f8f8ded3efbc Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Wed, 14 Mar 2018 22:15:24 -0700 Subject: [PATCH] Fixed Meta included in Enum members. Fixed #685 --- graphene/types/enum.py | 6 +++++- graphene/types/tests/test_enum.py | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/graphene/types/enum.py b/graphene/types/enum.py index da0b6240..67a3f6b2 100644 --- a/graphene/types/enum.py +++ b/graphene/types/enum.py @@ -27,7 +27,11 @@ class EnumOptions(BaseOptions): class EnumMeta(SubclassWithMeta_Meta): def __new__(cls, name, bases, classdict, **options): - enum = PyEnum(cls.__name__, OrderedDict(classdict, __eq__=eq_enum)) + enum_members = OrderedDict(classdict, __eq__=eq_enum) + # We remove the Meta attribute from the class to not collide + # with the enum values. + enum_members.pop('Meta', None) + enum = PyEnum(cls.__name__, enum_members) return SubclassWithMeta_Meta.__new__(cls, name, bases, OrderedDict(classdict, __enum__=enum), **options) def get(cls, value): diff --git a/graphene/types/tests/test_enum.py b/graphene/types/tests/test_enum.py index c4cf3b85..fdd5f4e4 100644 --- a/graphene/types/tests/test_enum.py +++ b/graphene/types/tests/test_enum.py @@ -80,7 +80,8 @@ def test_enum_from_builtin_enum_accepts_lambda_description(): return 'meh' if value == Episode.NEWHOPE else None PyEpisode = PyEnum('PyEpisode', 'NEWHOPE,EMPIRE,JEDI') - Episode = Enum.from_enum(PyEpisode, description=custom_description, deprecation_reason=custom_deprecation_reason) + Episode = Enum.from_enum(PyEpisode, description=custom_description, + deprecation_reason=custom_deprecation_reason) class Query(ObjectType): foo = Episode() @@ -214,3 +215,19 @@ def test_enum_to_enum_comparison_should_differ(): assert RGB1.RED != RGB2.RED assert RGB1.GREEN != RGB2.GREEN assert RGB1.BLUE != RGB2.BLUE + + +def test_enum_skip_meta_from_members(): + class RGB1(Enum): + class Meta: + name = 'RGB' + + RED = 1 + GREEN = 2 + BLUE = 3 + + assert dict(RGB1._meta.enum.__members__) == { + 'RED': RGB1.RED, + 'GREEN': RGB1.GREEN, + 'BLUE': RGB1.BLUE, + }