Skip to content

Commit 72b6e05

Browse files
authored
fix: 🐛 Handle python 3.12+ TypeAliasType in Option parsing (#2952)
* 🐛 Handle python 3.12+ `TypeAliasType` in `Option` parsing * 📝 CHANGELOG.md --------- Signed-off-by: Paillat <[email protected]>
1 parent c5fe3ee commit 72b6e05

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ These changes are available on the `master` branch, but have not yet been releas
5454
([#2938](https://github.com/Pycord-Development/pycord/pull/2938))
5555
- Fixed a KeyError when a text input is left blank in a modal.
5656
([#2938](https://github.com/Pycord-Development/pycord/pull/2938))
57+
- Fixed `TypeError` when using Python 3.12+ `type` syntax for typing slash command
58+
parameters. ([#2952](https://github.com/Pycord-Development/pycord/pull/2952))
5759

5860
### Removed
5961

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)