aboutsummaryrefslogtreecommitdiff
path: root/discord/http.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2021-04-16 08:02:19 -0400
committerRapptz <[email protected]>2021-04-16 08:02:19 -0400
commita30ec197c22299e28c0dabdd83b9d1f140efc16a (patch)
tree4ac28fae67c66d9d32a6cc6b9ee4a1b905a91395 /discord/http.py
parentAdd periods to sticker docs (diff)
downloaddiscord.py-a30ec197c22299e28c0dabdd83b9d1f140efc16a.tar.xz
discord.py-a30ec197c22299e28c0dabdd83b9d1f140efc16a.zip
Some initial response typings
Diffstat (limited to 'discord/http.py')
-rw-r--r--discord/http.py35
1 files changed, 24 insertions, 11 deletions
diff --git a/discord/http.py b/discord/http.py
index 1e64a191..6d6c641d 100644
--- a/discord/http.py
+++ b/discord/http.py
@@ -22,10 +22,13 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
+from __future__ import annotations
+
import asyncio
import json
import logging
import sys
+from typing import Any, Coroutine, List, TYPE_CHECKING, TypeVar
from urllib.parse import quote as _uriquote
import weakref
@@ -37,6 +40,14 @@ from . import __version__, utils
log = logging.getLogger(__name__)
+if TYPE_CHECKING:
+ from .types import (
+ interactions,
+ )
+
+ T = TypeVar('T')
+ Response = Coroutine[Any, Any, T]
+
async def json_or_text(response):
text = await response.text(encoding='utf-8')
@@ -138,7 +149,7 @@ class HTTPClient:
return await self.__session.ws_connect(url, **kwargs)
- async def request(self, route, *, files=None, form=None, **kwargs):
+ async def request(self, route, *, files=None, form=None, **kwargs) -> Any:
bucket = route.bucket
method = route.method
url = route.url
@@ -1039,10 +1050,10 @@ class HTTPClient:
# Application commands (global)
- def get_global_commands(self, application_id):
+ def get_global_commands(self, application_id) -> Response[List[interactions.ApplicationCommand]]:
return self.request(Route('GET', '/applications/{application_id}/commands', application_id=application_id))
- def get_global_command(self, application_id, command_id):
+ def get_global_command(self, application_id, command_id) -> Response[interactions.ApplicationCommand]:
r = Route(
'GET',
'/applications/{application_id}/commands/{command_id}',
@@ -1051,11 +1062,11 @@ class HTTPClient:
)
return self.request(r)
- def upsert_global_command(self, application_id, payload):
+ def upsert_global_command(self, application_id, payload) -> Response[interactions.ApplicationCommand]:
r = Route('POST', '/applications/{application_id}/commands', application_id=application_id)
return self.request(r, json=payload)
- def edit_global_command(self, application_id, command_id, payload):
+ def edit_global_command(self, application_id, command_id, payload) -> Response[interactions.ApplicationCommand]:
valid_keys = (
'name',
'description',
@@ -1079,13 +1090,13 @@ class HTTPClient:
)
return self.request(r)
- def bulk_upsert_global_commands(self, application_id, payload):
+ def bulk_upsert_global_commands(self, application_id, payload) -> Response[List[interactions.ApplicationCommand]]:
r = Route('PUT', '/applications/{application_id}/commands', application_id=application_id)
return self.request(r, json=payload)
# Application commands (guild)
- def get_guild_commands(self, application_id, guild_id):
+ def get_guild_commands(self, application_id, guild_id) -> Response[List[interactions.ApplicationCommand]]:
r = Route(
'GET',
'/applications/{application_id}/{guild_id}/commands',
@@ -1094,7 +1105,7 @@ class HTTPClient:
)
return self.request(r)
- def get_guild_command(self, application_id, guild_id, command_id):
+ def get_guild_command(self, application_id, guild_id, command_id) -> Response[interactions.ApplicationCommand]:
r = Route(
'GET',
'/applications/{application_id}/{guild_id}/commands/{command_id}',
@@ -1104,7 +1115,7 @@ class HTTPClient:
)
return self.request(r)
- def upsert_guild_command(self, application_id, guild_id, payload):
+ def upsert_guild_command(self, application_id, guild_id, payload) -> Response[interactions.ApplicationCommand]:
r = Route(
'POST',
'/applications/{application_id}/{guild_id}/commands',
@@ -1113,7 +1124,7 @@ class HTTPClient:
)
return self.request(r, json=payload)
- def edit_guild_command(self, application_id, guild_id, command_id, payload):
+ def edit_guild_command(self, application_id, guild_id, command_id, payload) -> Response[interactions.ApplicationCommand]:
valid_keys = (
'name',
'description',
@@ -1139,7 +1150,9 @@ class HTTPClient:
)
return self.request(r)
- def bulk_upsert_guild_commands(self, application_id, guild_id, payload):
+ def bulk_upsert_guild_commands(
+ self, application_id, guild_id, payload
+ ) -> Response[List[interactions.ApplicationCommand]]:
r = Route(
'PUT',
'/applications/{application_id}/{guild_id}/commands',