from_enum can now take a deprecation reason (#957)

This commit is contained in:
NyanKiyoshi 2019-05-06 19:17:33 +02:00 committed by Eran Kampf
parent abff3d75a3
commit 6a4091b3e4
2 changed files with 14 additions and 1 deletions

View File

@ -0,0 +1,8 @@
import graphene
def test_issue():
options = {"description": "This my enum", "deprecation_reason": "For the funs"}
new_enum = graphene.Enum("MyEnum", [("some", "data")], **options)
assert new_enum._meta.description == options["description"]
assert new_enum._meta.deprecation_reason == options["deprecation_reason"]

View File

@ -46,7 +46,12 @@ class EnumMeta(SubclassWithMeta_Meta):
def __call__(cls, *args, **kwargs): # noqa: N805
if cls is Enum:
description = kwargs.pop("description", None)
return cls.from_enum(PyEnum(*args, **kwargs), description=description)
deprecation_reason = kwargs.pop("deprecation_reason", None)
return cls.from_enum(
PyEnum(*args, **kwargs),
description=description,
deprecation_reason=deprecation_reason,
)
return super(EnumMeta, cls).__call__(*args, **kwargs)
# return cls._meta.enum(*args, **kwargs)