Skip to content

Commit 43d6976

Browse files
committed
🐛 Handle python 3.12+ TypeAliasType in Option parsing
1 parent 1d67b64 commit 43d6976

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

discord/commands/options.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,15 @@
2828
import logging
2929
import types
3030
from enum import Enum
31-
from typing import TYPE_CHECKING, Literal, Optional, Type, Union, get_args
31+
from typing import (
32+
TYPE_CHECKING,
33+
Literal,
34+
Optional,
35+
Type,
36+
TypeAliasType,
37+
Union,
38+
get_args,
39+
)
3240

3341
from ..abc import GuildChannel, Mentionable
3442
from ..channel import (
@@ -197,6 +205,7 @@ def __init__(
197205
if self.name is not None:
198206
self.name = str(self.name)
199207
self._parameter_name = self.name # default
208+
input_type = self._parse_type_alias(input_type)
200209
input_type = self._strip_none_type(input_type)
201210
self._raw_type: InputType | tuple = input_type
202211

@@ -367,6 +376,12 @@ def __init__(
367376
if input_type is None:
368377
raise TypeError("input_type cannot be NoneType.")
369378

379+
@staticmethod
380+
def _parse_type_alias(input_type: InputType) -> InputType:
381+
if isinstance(input_type, TypeAliasType):
382+
return input_type.__value__
383+
return input_type
384+
370385
@staticmethod
371386
def _strip_none_type(input_type):
372387
if isinstance(input_type, SlashCommandOptionType):

0 commit comments

Comments
 (0)