diff options
author | 2023-06-04 20:34:14 +0100 | |
---|---|---|
committer | 2023-06-04 20:34:14 +0100 | |
commit | 1a362c04eb4d5d8f3c531a590d73cf5d7300ace8 (patch) | |
tree | accbe4d840b036dcc9502eed395f19400f5ad9a3 /pydis_core/site_api.py | |
parent | Merge pull request #175 from python-discord/log-when-waiting-for-guild-to-be-... (diff) | |
parent | Add changelog entry for ruff migration (diff) |
Merge pull request #176 from python-discord/ruff-migration
Ruff migration
Diffstat (limited to 'pydis_core/site_api.py')
-rw-r--r-- | pydis_core/site_api.py | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/pydis_core/site_api.py b/pydis_core/site_api.py index c17d2642..80eeff2b 100644 --- a/pydis_core/site_api.py +++ b/pydis_core/site_api.py @@ -1,7 +1,6 @@ """An API wrapper around the Site API.""" import asyncio -from typing import Optional from urllib.parse import quote as quote_url import aiohttp @@ -17,8 +16,8 @@ class ResponseCodeError(ValueError): def __init__( self, response: aiohttp.ClientResponse, - response_json: Optional[dict] = None, - response_text: Optional[str] = None + response_json: dict | None = None, + response_text: str | None = None ): """ Initialize a new :obj:`ResponseCodeError` instance. @@ -42,7 +41,7 @@ class ResponseCodeError(ValueError): class APIClient: """A wrapper for the Django Site API.""" - session: Optional[aiohttp.ClientSession] = None + session: aiohttp.ClientSession | None = None loop: asyncio.AbstractEventLoop = None def __init__(self, site_api_url: str, site_api_token: str, **session_kwargs): @@ -57,13 +56,13 @@ class APIClient: self.site_api_url = site_api_url auth_headers = { - 'Authorization': f"Token {site_api_token}" + "Authorization": f"Token {site_api_token}" } - if 'headers' in session_kwargs: - session_kwargs['headers'].update(auth_headers) + if "headers" in session_kwargs: + session_kwargs["headers"].update(auth_headers) else: - session_kwargs['headers'] = auth_headers + session_kwargs["headers"] = auth_headers # aiohttp will complain if APIClient gets instantiated outside a coroutine. Thankfully, we # don't and shouldn't need to do that, so we can avoid scheduling a task to create it. @@ -134,7 +133,7 @@ class APIClient: """Equivalent to :meth:`APIClient.request` with PUT passed as the method.""" return await self.request("PUT", endpoint, raise_for_status=raise_for_status, **kwargs) - async def delete(self, endpoint: str, *, raise_for_status: bool = True, **kwargs) -> Optional[dict]: + async def delete(self, endpoint: str, *, raise_for_status: bool = True, **kwargs) -> dict | None: """ Send a DELETE request to the site API and return the JSON response. @@ -154,4 +153,4 @@ class APIClient: return await resp.json() -__all__ = ['APIClient', 'ResponseCodeError'] +__all__ = ["APIClient", "ResponseCodeError"] |