Skip to content

refactor: Remove unused and duplicate imports #2787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

import aiohttp

from . import __version__, utils
from . import __version__
from .errors import (
DiscordServerError,
Forbidden,
Expand All @@ -46,7 +46,13 @@
)
from .file import VoiceMessage
from .gateway import DiscordClientWebSocketResponse
from .utils import MISSING, warn_deprecated
from .utils import (
MISSING,
_from_json,
_get_mime_type_for_image,
_parse_ratelimit_header,
_to_json,
)

_log = logging.getLogger(__name__)

Expand Down Expand Up @@ -97,7 +103,7 @@ async def json_or_text(response: aiohttp.ClientResponse) -> dict[str, Any] | str
text = await response.text(encoding="utf-8")
try:
if response.headers["content-type"] == "application/json":
return utils._from_json(text)
return _from_json(text)
except KeyError:
# Thanks Cloudflare
pass
Expand Down Expand Up @@ -246,7 +252,7 @@ async def request(
# some checking if it's a JSON request
if "json" in kwargs:
headers["Content-Type"] = "application/json"
kwargs["data"] = utils._to_json(kwargs.pop("json"))
kwargs["data"] = _to_json(kwargs.pop("json"))

try:
reason = kwargs.pop("reason")
Expand Down Expand Up @@ -304,7 +310,7 @@ async def request(
remaining = response.headers.get("X-Ratelimit-Remaining")
if remaining == "0" and response.status != 429:
# we've depleted our current bucket
delta = utils._parse_ratelimit_header(
delta = _parse_ratelimit_header(
response, use_clock=self.use_clock
)
_log.debug(
Expand Down Expand Up @@ -590,7 +596,7 @@ def send_multipart_helper(
}
)
payload["attachments"] = attachments
form[0]["value"] = utils._to_json(payload)
form[0]["value"] = _to_json(payload)
return self.request(route, form=form, files=files)

def send_files(
Expand Down Expand Up @@ -663,7 +669,7 @@ def edit_multipart_helper(
payload["attachments"] = attachments
else:
payload["attachments"].extend(attachments)
form[0]["value"] = utils._to_json(payload)
form[0]["value"] = _to_json(payload)

return self.request(route, form=form, files=files)

Expand Down Expand Up @@ -1295,7 +1301,7 @@ def start_forum_thread(
)

payload["attachments"] = attachments
form[0]["value"] = utils._to_json(payload)
form[0]["value"] = _to_json(payload)
return self.request(route, form=form, reason=reason)
return self.request(route, json=payload, reason=reason)

Expand Down Expand Up @@ -1762,7 +1768,7 @@ def create_guild_sticker(
initial_bytes = file.fp.read(16)

try:
mime_type = utils._get_mime_type_for_image(initial_bytes)
mime_type = _get_mime_type_for_image(initial_bytes)
except InvalidArgument:
if initial_bytes.startswith(b"{"):
mime_type = "application/json"
Expand Down Expand Up @@ -2764,7 +2770,7 @@ def _edit_webhook_helper(
form: list[dict[str, Any]] = [
{
"name": "payload_json",
"value": utils._to_json(payload),
"value": _to_json(payload),
}
]

Expand Down