Skip to content

Commit

Permalink
refactor: remove _modify_api_version (nextcord#1115)
Browse files Browse the repository at this point in the history
* refactor: remove _modify_api_version

* style: auto fixes from pre-commit hooks

* typing: constrain _API_VERSION to just v10

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
EmmmaTech and pre-commit-ci[bot] committed Sep 30, 2023
1 parent 5d2eff1 commit 308e827
Showing 1 changed file with 2 additions and 35 deletions.
37 changes: 2 additions & 35 deletions nextcord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import asyncio
import logging
import sys
import warnings
import weakref
from typing import (
TYPE_CHECKING,
Expand Down Expand Up @@ -95,43 +94,11 @@ async def json_or_text(response: aiohttp.ClientResponse) -> Union[Dict[str, Any]

_DEFAULT_API_VERSION = 10

_API_VERSION: Literal[9, 10] = _DEFAULT_API_VERSION


class UnsupportedAPIVersion(UserWarning):
"""Warning category raised when changing the API version to an unsupported version."""


def _modify_api_version(version: Literal[9, 10]):
"""Modify the API version used by the HTTP client.
Additional versions may be added around the time of a Discord API
version bump to allow temporarily downgrading to an older API version
or upgrading to a newer version that is not yet supported by the library.
Changing the API version from the default is not supported and may result in
unexpected behaviour.
"""
available_versions = (9, 10)

if version not in available_versions:
raise ValueError(f"Only API versions {available_versions} are available.")

if version != _DEFAULT_API_VERSION:
warnings.warn(
"Changing the API version is not supported and may result in unexpected behaviour.",
category=UnsupportedAPIVersion,
stacklevel=2,
)

global _API_VERSION
_API_VERSION = version

Route.BASE = f"https://discord.com/api/v{version}"
_API_VERSION: Literal[10] = _DEFAULT_API_VERSION


class Route:
BASE: ClassVar[str] = f"https://discord.com/api/v{_DEFAULT_API_VERSION}"
BASE: ClassVar[str] = f"https://discord.com/api/v{_API_VERSION}"

def __init__(self, method: str, path: str, **parameters: Any) -> None:
self.path: str = path
Expand Down

0 comments on commit 308e827

Please sign in to comment.