mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-26 03:23:55 +03:00
Fixed Enum value getter
This commit is contained in:
parent
449b8c67d1
commit
50c1ab62ba
|
@ -55,11 +55,12 @@ class EnumTypeMeta(ClassTypeMeta):
|
|||
def construct(cls, bases, attrs):
|
||||
if not cls._meta.enum:
|
||||
cls._meta.enum = type(cls.__name__, (PyEnum,), attrs)
|
||||
return super(EnumTypeMeta, cls).construct(bases, {})
|
||||
|
||||
return super(EnumTypeMeta, cls).construct(bases, cls._meta.enum.__members__)
|
||||
|
||||
def __call__(cls, *args, **kwargs):
|
||||
if cls is Enum:
|
||||
return Enum.create(PyEnum(*args, **kwargs))
|
||||
if cls._meta.abstract:
|
||||
return cls.create(PyEnum(*args, **kwargs))
|
||||
return super(EnumTypeMeta, cls).__call__(*args, **kwargs)
|
||||
|
||||
def create(cls, python_enum):
|
||||
|
@ -71,6 +72,3 @@ class EnumTypeMeta(ClassTypeMeta):
|
|||
class Enum(six.with_metaclass(EnumTypeMeta, TypeProxy)):
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def __getattr__(self, name):
|
||||
return getattr(self._meta.enum, name)
|
||||
|
|
|
@ -50,3 +50,12 @@ def test_enum_from_builtin_enum():
|
|||
]
|
||||
assert isinstance(RGB(name='field_name').as_field(), Field)
|
||||
assert isinstance(RGB(name='field_name').as_argument(), Argument)
|
||||
|
||||
|
||||
def test_enum_value_from_class():
|
||||
class RGB(Enum):
|
||||
RED = 1
|
||||
GREEN = 2
|
||||
BLUE = 3
|
||||
|
||||
assert RGB.RED.value == 1
|
||||
|
|
Loading…
Reference in New Issue
Block a user