From 8699436fd2bf1bc648200b50a4b6280e45f6f022 Mon Sep 17 00:00:00 2001 From: Chiggy-Playz Date: Wed, 13 Oct 2021 00:36:32 +0530 Subject: [PATCH 1/2] Fix Optional Literal not showing choices --- discord/ext/commands/core.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index 9650bd6f..50c3a481 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -1242,9 +1242,10 @@ class Command(_BaseCommand, Generic[CogT, P, T]): annotation = str origin = None - if not required and origin is not None and len(annotation.__args__) == 2: + if not required and origin is Union and annotation.__args__[-1] is type(None): # Unpack Optional[T] (Union[T, None]) into just T - annotation, origin = annotation.__args__[0], None + annotation = annotation.__args__[0] + origin = getattr(annotation, '__origin__', None) option: Dict[str, Any] = { "type": 3, -- 2.47.2 From 80775db1a443e5564067c64633c98966c137cd42 Mon Sep 17 00:00:00 2001 From: Chiggy-Playz Date: Wed, 13 Oct 2021 00:56:08 +0530 Subject: [PATCH 2/2] Format with black --- discord/ext/commands/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index 50c3a481..30b75198 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -1245,7 +1245,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]): if not required and origin is Union and annotation.__args__[-1] is type(None): # Unpack Optional[T] (Union[T, None]) into just T annotation = annotation.__args__[0] - origin = getattr(annotation, '__origin__', None) + origin = getattr(annotation, "__origin__", None) option: Dict[str, Any] = { "type": 3, -- 2.47.2