Skip to content

Commit b3916c7

Browse files
committed
fix: 🐛 Handle python 3.12+ TypeAliasType in Option parsing (Pycord-Development#2952)
* 🐛 Handle python 3.12+ `TypeAliasType` in `Option` parsing * 📝 CHANGELOG.md --------- Signed-off-by: Paillat <[email protected]> (cherry picked from commit 72b6e05)
1 parent f4d9b03 commit b3916c7

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ These changes are available on the `master` branch, but have not yet been releas
2828
- Adds pre-typed and pre-constructed with select_type `ui.Select` aliases for the
2929
different select types: `ui.StringSelect`, `ui.UserSelect`, `ui.RoleSelect`,
3030
`ui.MentionableSelect`, and `ui.ChannelSelect`.
31+
- Added `ui.FileUpload` for modals and the `FileUpload` component.
32+
([#2938](https://github.com/Pycord-Development/pycord/pull/2938))
3133

3234
### Changed
3335

@@ -45,6 +47,15 @@ These changes are available on the `master` branch, but have not yet been releas
4547
([#2924](https://github.com/Pycord-Development/pycord/pull/2924))
4648
- Fixed OPUS Decode Error when recording audio.
4749
([#2925](https://github.com/Pycord-Development/pycord/pull/2925))
50+
- Fixed a `TypeError` when typing `ui.Select` without providing optional type arguments.
51+
([#2943](https://github.com/Pycord-Development/pycord/pull/2943))
52+
- Fixed modal input values being misordered when using the `row` parameter and inserting
53+
items out of row order.
54+
([#2938](https://github.com/Pycord-Development/pycord/pull/2938))
55+
- Fixed a KeyError when a text input is left blank in a modal.
56+
([#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))
4859

4960
### Removed
5061

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 (
@@ -194,6 +202,7 @@ def __init__(self, input_type: InputType = str, /, description: str | None = Non
194202
if self.name is not None:
195203
self.name = str(self.name)
196204
self._parameter_name = self.name # default
205+
input_type = self._parse_type_alias(input_type)
197206
input_type = self._strip_none_type(input_type)
198207
self._raw_type: InputType | tuple = input_type
199208

@@ -331,6 +340,12 @@ def __init__(self, input_type: InputType = str, /, description: str | None = Non
331340
if input_type is None:
332341
raise TypeError("input_type cannot be NoneType.")
333342

343+
@staticmethod
344+
def _parse_type_alias(input_type: InputType) -> InputType:
345+
if isinstance(input_type, TypeAliasType):
346+
return input_type.__value__
347+
return input_type
348+
334349
@staticmethod
335350
def _strip_none_type(input_type):
336351
if isinstance(input_type, SlashCommandOptionType):

0 commit comments

Comments
 (0)