Skip to content

Commit

Permalink
Revert "Merge core/typing (Pycord-Development#432)"
Browse files Browse the repository at this point in the history
This reverts commit 6e65959.
  • Loading branch information
krittick committed Jan 27, 2022
1 parent 6e65959 commit 392d17d
Show file tree
Hide file tree
Showing 27 changed files with 497 additions and 987 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.10' ]
python-version: [ 3.8 ]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -17,7 +17,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install -U pip
pip install -U sphinx sphinxcontrib-trio aiohttp sphinxcontrib-websupport myst-parser typing-extensions
pip install -U sphinx sphinxcontrib-trio aiohttp sphinxcontrib-websupport myst-parser
- name: Compile to html
run: |
cd docs
Expand Down
4 changes: 2 additions & 2 deletions discord/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,11 @@ def __str__(self) -> str:
def __len__(self) -> int:
return len(self._url)

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

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

def __hash__(self):
Expand Down
1 change: 0 additions & 1 deletion discord/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
Type,
TypeVar,
Union,
Type,
)

from .client import Client
Expand Down
16 changes: 0 additions & 16 deletions discord/commands/_types.py

This file was deleted.

133 changes: 51 additions & 82 deletions discord/commands/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,22 @@
"""
from __future__ import annotations

from typing import TYPE_CHECKING, Optional, Union, TypeVar, Generic, Callable, List, Any, Dict
from typing import TYPE_CHECKING, Optional, TypeVar, Union

import discord.utils
import discord.abc

if TYPE_CHECKING:
from . import ApplicationCommand, Option
from ..cog import Cog
from ..embeds import Embed
from ..file import File
from ..guild import Guild
from ..interactions import Interaction, InteractionChannel, InteractionResponse, InteractionMessage
from ..member import Member
from ..mentions import AllowedMentions
from ..message import Message
from ..state import ConnectionState
from ..user import User
from ..ui import View
from ..voice_client import VoiceProtocol
from ..webhook import Webhook, WebhookMessage
from typing_extensions import ParamSpec

import discord
from discord import Bot
from discord.state import ConnectionState

from .core import ApplicationCommand, Option
from ..cog import Cog
from ..webhook import WebhookMessage
from typing import Callable

from ..guild import Guild
from ..interactions import Interaction, InteractionResponse
from ..member import Member
Expand All @@ -63,18 +58,7 @@
__all__ = ("ApplicationContext", "AutocompleteContext")


MISSING: Any = discord.utils.MISSING

T = TypeVar("T")
BotT = TypeVar("BotT", bound="Union[discord.Bot, discord.AutoShardedBot]")
CogT = TypeVar("CogT", bound="Cog")

if TYPE_CHECKING:
P = ParamSpec('P')
else:
P = TypeVar('P')

class ApplicationContext(discord.abc.Messageable, Generic[BotT]):
class ApplicationContext(discord.abc.Messageable):
"""Represents a Discord application command interaction context.
This class is not created manually and is instead passed to application
Expand All @@ -92,9 +76,9 @@ class ApplicationContext(discord.abc.Messageable, Generic[BotT]):
The command that this context belongs to.
"""

def __init__(self, bot: BotT, interaction: Interaction) -> None:
self.bot: BotT = bot
self.interaction: Interaction = interaction
def __init__(self, bot: Bot, interaction: Interaction):
self.bot = bot
self.interaction = interaction

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

self._state: ConnectionState = self.interaction._state

async def _get_channel(self) -> Optional[InteractionChannel]:
async def _get_channel(self) -> discord.abc.Messageable:
return self.channel

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

@cached_property
def channel(self) -> Optional[InteractionChannel]:
def channel(self):
return self.interaction.channel

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

@cached_property
def locale(self) -> Optional[str]:
return self.interaction.locale

@cached_property
def guild_locale(self) -> Optional[str]:
return self.interaction.guild_locale

@cached_property
def me(self) -> Union[Member, User]:
return self.guild.me if self.guild is not None else self.bot.user
Expand Down Expand Up @@ -176,14 +168,6 @@ def voice_client(self):
def response(self) -> InteractionResponse:
return self.interaction.response

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

return self.command.cog

@property
def respond(self) -> Callable[..., Union[Interaction, WebhookMessage]]:
"""Callable[..., Union[:class:`~.Interaction`, :class:`~.Webhook`]]: Sends either a response
Expand Down Expand Up @@ -211,42 +195,33 @@ def send_followup(self):
f"Interaction was not yet issued a response. Try using {type(self).__name__}.respond() first."
)

@discord.utils.copy_doc(InteractionResponse.defer)
async def defer(self, *, ephemeral: bool = False) -> None:
return await self.interaction.response.defer(ephemeral=ephemeral)
@property
def defer(self):
return self.interaction.response.defer

@property
def followup(self) -> Webhook:
def followup(self):
return self.interaction.followup

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

return await self.interaction.delete_original_message()

async def edit(
self,
*,
content: Optional[str] = MISSING,
embeds: List[Embed] = MISSING,
embed: Optional[Embed] = MISSING,
file: File = MISSING,
files: List[File] = MISSING,
view: Optional[View] = MISSING,
allowed_mentions: Optional[AllowedMentions] = None,
) -> InteractionMessage:
return await self.interaction.edit_original_message(
content=content,
embeds=embeds,
embed=embed,
file=file,
files=files,
view=view,
allowed_mentions=allowed_mentions,
)
@property
def edit(self):
return self.interaction.edit_original_message

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

return self.command.cog


class AutocompleteContext:
Expand All @@ -273,24 +248,18 @@ class AutocompleteContext:
"""

__slots__ = ("bot", "interaction", "command", "focused", "value", "options")

def __init__(
self,
interaction: Interaction,
*,
command: ApplicationCommand,
focused: Option,
value: str,
options: Dict[str, Any],
) -> None:
self.interaction: Interaction = interaction
self.command: ApplicationCommand = command
self.focused: Option = focused
self.value: str = value
self.options: Dict[str, Any] = options

def __init__(self, bot: Bot, interaction: Interaction) -> None:
self.bot = bot
self.interaction = interaction

self.command: ApplicationCommand = None # type: ignore
self.focused: Option = None # type: ignore
self.value: str = None # type: ignore
self.options: dict = None # type: ignore

@property
def cog(self) -> Optional[CogT]:
def cog(self) -> Optional[Cog]:
"""Optional[:class:`.Cog`]: Returns the cog associated with this context's command. ``None`` if it does not exist."""
if self.command is None:
return None
Expand Down
Loading

0 comments on commit 392d17d

Please sign in to comment.