|
26 | 26 | from __future__ import annotations
|
27 | 27 |
|
28 | 28 | import asyncio
|
| 29 | +from collections.abc import Iterator |
29 | 30 | import datetime
|
30 | 31 | import functools
|
31 | 32 | import inspect
|
|
50 | 51 | from ..enums import (
|
51 | 52 | IntegrationType,
|
52 | 53 | InteractionContextType,
|
53 |
| - MessageType, |
54 | 54 | SlashCommandOptionType,
|
55 |
| - try_enum, |
56 | 55 | )
|
57 | 56 | from ..errors import (
|
58 | 57 | ApplicationCommandError,
|
|
62 | 61 | InvalidArgument,
|
63 | 62 | ValidationError,
|
64 | 63 | )
|
65 |
| -from ..member import Member |
66 | 64 | from ..message import Attachment, Message
|
67 | 65 | from ..object import Object
|
68 | 66 | from ..role import Role
|
69 | 67 | from ..threads import Thread
|
70 | 68 | from ..user import User
|
71 |
| -from ..utils import MISSING, async_all, find, maybe_coroutine, utcnow, warn_deprecated |
| 69 | +from ..utils import MISSING, async_all, find, maybe_coroutine, resolve_annotation, utcnow, warn_deprecated |
72 | 70 | from .context import ApplicationContext, AutocompleteContext
|
73 | 71 | from .options import Option, OptionChoice
|
74 | 72 |
|
|
101 | 99 |
|
102 | 100 | T = TypeVar("T")
|
103 | 101 | CogT = TypeVar("CogT", bound="Cog")
|
104 |
| -Coro = TypeVar("Coro", bound=Callable[..., Coroutine[Any, Any, Any]]) |
| 102 | +Coro = Coroutine[Any, Any, T] |
105 | 103 |
|
106 | 104 | if TYPE_CHECKING:
|
107 | 105 | P = ParamSpec("P")
|
@@ -190,7 +188,7 @@ class ApplicationCommand(_BaseCommand, Generic[CogT, P, T]):
|
190 | 188 | cog = None
|
191 | 189 |
|
192 | 190 | def __init__(self, func: Callable, **kwargs) -> None:
|
193 |
| - from ..ext.commands.cooldowns import BucketType, CooldownMapping, MaxConcurrency |
| 191 | + from ..ext.commands.cooldowns import BucketType, CooldownMapping |
194 | 192 |
|
195 | 193 | cooldown = getattr(func, "__commands_cooldown__", kwargs.get("cooldown"))
|
196 | 194 |
|
@@ -314,7 +312,7 @@ def guild_only(self) -> bool:
|
314 | 312 | "2.6",
|
315 | 313 | reference="https://discord.com/developers/docs/change-log#userinstallable-apps-preview",
|
316 | 314 | )
|
317 |
| - return InteractionContextType.guild in self.contexts and len(self.contexts) == 1 |
| 315 | + return self.contexts is not None and InteractionContextType.guild in self.contexts and len(self.contexts) == 1 |
318 | 316 |
|
319 | 317 | @guild_only.setter
|
320 | 318 | def guild_only(self, value: bool) -> None:
|
@@ -779,33 +777,36 @@ def _validate_parameters(self):
|
779 | 777 | else:
|
780 | 778 | self.options = self._parse_options(params)
|
781 | 779 |
|
782 |
| - def _check_required_params(self, params): |
783 |
| - params = iter(params.items()) |
| 780 | + def _check_required_params(self, params: OrderedDict[str, inspect.Parameter]) -> Iterator[tuple[str, inspect.Parameter]]: |
| 781 | + params_iter = iter(params.items()) |
784 | 782 | required_params = (
|
785 | 783 | ["self", "context"] if self.attached_to_group or self.cog else ["context"]
|
786 | 784 | )
|
787 | 785 | for p in required_params:
|
788 | 786 | try:
|
789 |
| - next(params) |
| 787 | + next(params_iter) |
790 | 788 | except StopIteration:
|
791 | 789 | raise ClientException(
|
792 | 790 | f'Callback for {self.name} command is missing "{p}" parameter.'
|
793 | 791 | )
|
794 | 792 |
|
795 |
| - return params |
| 793 | + return params_iter |
796 | 794 |
|
797 |
| - def _parse_options(self, params, *, check_params: bool = True) -> list[Option]: |
| 795 | + def _parse_options(self, params: OrderedDict[str, inspect.Parameter], *, check_params: bool = True) -> list[Option]: |
798 | 796 | if check_params:
|
799 |
| - params = self._check_required_params(params) |
| 797 | + params_iter = self._check_required_params(params) |
800 | 798 | else:
|
801 |
| - params = iter(params.items()) |
| 799 | + params_iter = iter(params.items()) |
802 | 800 |
|
803 | 801 | final_options = []
|
804 |
| - for p_name, p_obj in params: |
| 802 | + cache = {} |
| 803 | + for p_name, p_obj in params_iter: |
805 | 804 | option = p_obj.annotation
|
806 | 805 | if option == inspect.Parameter.empty:
|
807 | 806 | option = str
|
808 | 807 |
|
| 808 | + option = resolve_annotation(option, globals(), locals(), cache) |
| 809 | + |
809 | 810 | option = Option._strip_none_type(option)
|
810 | 811 | if self._is_typing_literal(option):
|
811 | 812 | literal_values = get_args(option)
|
|
0 commit comments