Fixed Meta included in Enum members. Fixed #685

This commit is contained in:
Syrus Akbary 2018-03-14 22:15:24 -07:00
parent d6df14923d
commit 2594cdb614
2 changed files with 23 additions and 2 deletions

View File

@ -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):

View File

@ -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,
}