From 8ede21e06381c096589c424960a6cfaca304badb Mon Sep 17 00:00:00 2001 From: Firas Kafri <3097061+firaskafri@users.noreply.github.com> Date: Thu, 25 May 2023 13:21:55 +0300 Subject: [PATCH] chore: default enum description to "An enumeration." (#1502) * Default enum description to "An enumeration." default to this string, which is used in many tests, is causing * Use the docstring descriptions of enums when they are present * Added tests * chore: add missing newline * Fix new line --------- Co-authored-by: Erik Wrede --- graphene/types/enum.py | 2 +- graphene/types/tests/test_enum.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/graphene/types/enum.py b/graphene/types/enum.py index 58e65c69e..7d68ccd48 100644 --- a/graphene/types/enum.py +++ b/graphene/types/enum.py @@ -63,7 +63,7 @@ def from_enum( cls, enum, name=None, description=None, deprecation_reason=None ): # noqa: N805 name = name or enum.__name__ - description = description or enum.__doc__ + description = description or enum.__doc__ or "An enumeration." meta_dict = { "enum": enum, "description": description, diff --git a/graphene/types/tests/test_enum.py b/graphene/types/tests/test_enum.py index 9b3082df1..e6fce66c9 100644 --- a/graphene/types/tests/test_enum.py +++ b/graphene/types/tests/test_enum.py @@ -65,6 +65,21 @@ def test_enum_from_builtin_enum(): assert RGB.BLUE +def test_enum_custom_description_in_constructor(): + description = "An enumeration, but with a custom description" + RGB = Enum( + "RGB", + "RED,GREEN,BLUE", + description=description, + ) + assert RGB._meta.description == description + + +def test_enum_from_python3_enum_uses_default_builtin_doc(): + RGB = Enum("RGB", "RED,GREEN,BLUE") + assert RGB._meta.description == "An enumeration." + + def test_enum_from_builtin_enum_accepts_lambda_description(): def custom_description(value): if not value: