Skip to content

Commit 213058a

Browse files
authored
Merge pull request #864 from krittick/revert-432
Revert "Merge core/typing (#432)"
2 parents 6e65959 + 392d17d commit 213058a

27 files changed

+497
-987
lines changed

.github/workflows/docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
python-version: [ '3.10' ]
10+
python-version: [ 3.8 ]
1111
steps:
1212
- uses: actions/checkout@v2
1313
- name: Set up Python ${{ matrix.python-version }}
@@ -17,7 +17,7 @@ jobs:
1717
- name: Install dependencies
1818
run: |
1919
python -m pip install -U pip
20-
pip install -U sphinx sphinxcontrib-trio aiohttp sphinxcontrib-websupport myst-parser typing-extensions
20+
pip install -U sphinx sphinxcontrib-trio aiohttp sphinxcontrib-websupport myst-parser
2121
- name: Compile to html
2222
run: |
2323
cd docs

discord/asset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,11 @@ def __str__(self) -> str:
268268
def __len__(self) -> int:
269269
return len(self._url)
270270

271-
def __repr__(self) -> str:
271+
def __repr__(self):
272272
shorten = self._url.replace(self.BASE, '')
273273
return f'<Asset url={shorten!r}>'
274274

275-
def __eq__(self, other) -> bool:
275+
def __eq__(self, other):
276276
return isinstance(other, Asset) and self._url == other._url
277277

278278
def __hash__(self):

discord/bot.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
Type,
4141
TypeVar,
4242
Union,
43-
Type,
4443
)
4544

4645
from .client import Client

discord/commands/_types.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

discord/commands/context.py

Lines changed: 51 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,22 @@
2424
"""
2525
from __future__ import annotations
2626

27-
from typing import TYPE_CHECKING, Optional, Union, TypeVar, Generic, Callable, List, Any, Dict
27+
from typing import TYPE_CHECKING, Optional, TypeVar, Union
2828

29-
import discord.utils
29+
import discord.abc
3030

3131
if TYPE_CHECKING:
32-
from . import ApplicationCommand, Option
33-
from ..cog import Cog
34-
from ..embeds import Embed
35-
from ..file import File
36-
from ..guild import Guild
37-
from ..interactions import Interaction, InteractionChannel, InteractionResponse, InteractionMessage
38-
from ..member import Member
39-
from ..mentions import AllowedMentions
40-
from ..message import Message
41-
from ..state import ConnectionState
42-
from ..user import User
43-
from ..ui import View
44-
from ..voice_client import VoiceProtocol
45-
from ..webhook import Webhook, WebhookMessage
4632
from typing_extensions import ParamSpec
4733

34+
import discord
35+
from discord import Bot
36+
from discord.state import ConnectionState
37+
38+
from .core import ApplicationCommand, Option
39+
from ..cog import Cog
40+
from ..webhook import WebhookMessage
41+
from typing import Callable
42+
4843
from ..guild import Guild
4944
from ..interactions import Interaction, InteractionResponse
5045
from ..member import Member
@@ -63,18 +58,7 @@
6358
__all__ = ("ApplicationContext", "AutocompleteContext")
6459

6560

66-
MISSING: Any = discord.utils.MISSING
67-
68-
T = TypeVar("T")
69-
BotT = TypeVar("BotT", bound="Union[discord.Bot, discord.AutoShardedBot]")
70-
CogT = TypeVar("CogT", bound="Cog")
71-
72-
if TYPE_CHECKING:
73-
P = ParamSpec('P')
74-
else:
75-
P = TypeVar('P')
76-
77-
class ApplicationContext(discord.abc.Messageable, Generic[BotT]):
61+
class ApplicationContext(discord.abc.Messageable):
7862
"""Represents a Discord application command interaction context.
7963
8064
This class is not created manually and is instead passed to application
@@ -92,9 +76,9 @@ class ApplicationContext(discord.abc.Messageable, Generic[BotT]):
9276
The command that this context belongs to.
9377
"""
9478

95-
def __init__(self, bot: BotT, interaction: Interaction) -> None:
96-
self.bot: BotT = bot
97-
self.interaction: Interaction = interaction
79+
def __init__(self, bot: Bot, interaction: Interaction):
80+
self.bot = bot
81+
self.interaction = interaction
9882

9983
# below attributes will be set after initialization
10084
self.command: ApplicationCommand = None # type: ignore
@@ -104,7 +88,7 @@ def __init__(self, bot: BotT, interaction: Interaction) -> None:
10488

10589
self._state: ConnectionState = self.interaction._state
10690

107-
async def _get_channel(self) -> Optional[InteractionChannel]:
91+
async def _get_channel(self) -> discord.abc.Messageable:
10892
return self.channel
10993

11094
async def invoke(self, command: ApplicationCommand[CogT, P, T], /, *args: P.args, **kwargs: P.kwargs) -> T:
@@ -134,7 +118,7 @@ async def invoke(self, command: ApplicationCommand[CogT, P, T], /, *args: P.args
134118
return await command(self, *args, **kwargs)
135119

136120
@cached_property
137-
def channel(self) -> Optional[InteractionChannel]:
121+
def channel(self):
138122
return self.interaction.channel
139123

140124
@cached_property
@@ -149,6 +133,14 @@ def guild(self) -> Optional[Guild]:
149133
def guild_id(self) -> Optional[int]:
150134
return self.interaction.guild_id
151135

136+
@cached_property
137+
def locale(self) -> Optional[str]:
138+
return self.interaction.locale
139+
140+
@cached_property
141+
def guild_locale(self) -> Optional[str]:
142+
return self.interaction.guild_locale
143+
152144
@cached_property
153145
def me(self) -> Union[Member, User]:
154146
return self.guild.me if self.guild is not None else self.bot.user
@@ -176,14 +168,6 @@ def voice_client(self):
176168
def response(self) -> InteractionResponse:
177169
return self.interaction.response
178170

179-
@property
180-
def cog(self) -> Optional[Cog]:
181-
"""Optional[:class:`.Cog`]: Returns the cog associated with this context's command. ``None`` if it does not exist."""
182-
if self.command is None:
183-
return None
184-
185-
return self.command.cog
186-
187171
@property
188172
def respond(self) -> Callable[..., Union[Interaction, WebhookMessage]]:
189173
"""Callable[..., Union[:class:`~.Interaction`, :class:`~.Webhook`]]: Sends either a response
@@ -211,42 +195,33 @@ def send_followup(self):
211195
f"Interaction was not yet issued a response. Try using {type(self).__name__}.respond() first."
212196
)
213197

214-
@discord.utils.copy_doc(InteractionResponse.defer)
215-
async def defer(self, *, ephemeral: bool = False) -> None:
216-
return await self.interaction.response.defer(ephemeral=ephemeral)
198+
@property
199+
def defer(self):
200+
return self.interaction.response.defer
217201

218202
@property
219-
def followup(self) -> Webhook:
203+
def followup(self):
220204
return self.interaction.followup
221205

222-
async def delete(self) -> None:
206+
async def delete(self):
223207
"""Calls :attr:`~discord.commands.ApplicationContext.respond`.
224208
If the response is done, then calls :attr:`~discord.commands.ApplicationContext.respond` first."""
225209
if not self.response.is_done():
226210
await self.defer()
227211

228212
return await self.interaction.delete_original_message()
229213

230-
async def edit(
231-
self,
232-
*,
233-
content: Optional[str] = MISSING,
234-
embeds: List[Embed] = MISSING,
235-
embed: Optional[Embed] = MISSING,
236-
file: File = MISSING,
237-
files: List[File] = MISSING,
238-
view: Optional[View] = MISSING,
239-
allowed_mentions: Optional[AllowedMentions] = None,
240-
) -> InteractionMessage:
241-
return await self.interaction.edit_original_message(
242-
content=content,
243-
embeds=embeds,
244-
embed=embed,
245-
file=file,
246-
files=files,
247-
view=view,
248-
allowed_mentions=allowed_mentions,
249-
)
214+
@property
215+
def edit(self):
216+
return self.interaction.edit_original_message
217+
218+
@property
219+
def cog(self) -> Optional[Cog]:
220+
"""Optional[:class:`.Cog`]: Returns the cog associated with this context's command. ``None`` if it does not exist."""
221+
if self.command is None:
222+
return None
223+
224+
return self.command.cog
250225

251226

252227
class AutocompleteContext:
@@ -273,24 +248,18 @@ class AutocompleteContext:
273248
"""
274249

275250
__slots__ = ("bot", "interaction", "command", "focused", "value", "options")
276-
277-
def __init__(
278-
self,
279-
interaction: Interaction,
280-
*,
281-
command: ApplicationCommand,
282-
focused: Option,
283-
value: str,
284-
options: Dict[str, Any],
285-
) -> None:
286-
self.interaction: Interaction = interaction
287-
self.command: ApplicationCommand = command
288-
self.focused: Option = focused
289-
self.value: str = value
290-
self.options: Dict[str, Any] = options
251+
252+
def __init__(self, bot: Bot, interaction: Interaction) -> None:
253+
self.bot = bot
254+
self.interaction = interaction
255+
256+
self.command: ApplicationCommand = None # type: ignore
257+
self.focused: Option = None # type: ignore
258+
self.value: str = None # type: ignore
259+
self.options: dict = None # type: ignore
291260

292261
@property
293-
def cog(self) -> Optional[CogT]:
262+
def cog(self) -> Optional[Cog]:
294263
"""Optional[:class:`.Cog`]: Returns the cog associated with this context's command. ``None`` if it does not exist."""
295264
if self.command is None:
296265
return None

0 commit comments

Comments
 (0)