Skip to content
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion discord/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2087,7 +2087,7 @@ async def connect(

try:
await voice.connect(timeout=timeout, reconnect=reconnect)
except asyncio.TimeoutError:
except TimeoutError:
try:
await voice.disconnect(force=True)
except Exception:
Expand Down
20 changes: 8 additions & 12 deletions discord/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def created_at(self) -> datetime.datetime | None:
"""
if self._created_at is not None:
return datetime.datetime.fromtimestamp(
self._created_at / 1000, tz=datetime.timezone.utc
self._created_at / 1000, tz=datetime.UTC
)

def to_dict(self) -> ActivityPayload:
Expand Down Expand Up @@ -288,7 +288,7 @@ def start(self) -> datetime.datetime | None:
except KeyError:
return None
else:
return datetime.datetime.fromtimestamp(timestamp, tz=datetime.timezone.utc)
return datetime.datetime.fromtimestamp(timestamp, tz=datetime.UTC)

@property
def end(self) -> datetime.datetime | None:
Expand All @@ -298,7 +298,7 @@ def end(self) -> datetime.datetime | None:
except KeyError:
return None
else:
return datetime.datetime.fromtimestamp(timestamp, tz=datetime.timezone.utc)
return datetime.datetime.fromtimestamp(timestamp, tz=datetime.UTC)

@property
def large_image_url(self) -> str | None:
Expand Down Expand Up @@ -398,18 +398,14 @@ def type(self) -> ActivityType:
def start(self) -> datetime.datetime | None:
"""When the user started playing this game in UTC, if applicable."""
if self._start:
return datetime.datetime.fromtimestamp(
self._start / 1000, tz=datetime.timezone.utc
)
return datetime.datetime.fromtimestamp(self._start / 1000, tz=datetime.UTC)
return None

@property
def end(self) -> datetime.datetime | None:
"""When the user will stop playing this game in UTC, if applicable."""
if self._end:
return datetime.datetime.fromtimestamp(
self._end / 1000, tz=datetime.timezone.utc
)
return datetime.datetime.fromtimestamp(self._end / 1000, tz=datetime.UTC)
return None

def __str__(self) -> str:
Expand Down Expand Up @@ -606,7 +602,7 @@ def created_at(self) -> datetime.datetime | None:
"""
if self._created_at is not None:
return datetime.datetime.fromtimestamp(
self._created_at / 1000, tz=datetime.timezone.utc
self._created_at / 1000, tz=datetime.UTC
)

@property
Expand Down Expand Up @@ -713,14 +709,14 @@ def track_url(self) -> str:
def start(self) -> datetime.datetime:
"""When the user started playing this song in UTC."""
return datetime.datetime.fromtimestamp(
self._timestamps["start"] / 1000, tz=datetime.timezone.utc
self._timestamps["start"] / 1000, tz=datetime.UTC
)

@property
def end(self) -> datetime.datetime:
"""When the user will stop playing this song in UTC."""
return datetime.datetime.fromtimestamp(
self._timestamps["end"] / 1000, tz=datetime.timezone.utc
self._timestamps["end"] / 1000, tz=datetime.UTC
)

@property
Expand Down
4 changes: 2 additions & 2 deletions discord/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
from .utils import MISSING, async_all, find, get

if TYPE_CHECKING:
from typing_extensions import Never
from typing import Never

from .cog import Cog
from .commands import Option
Expand Down Expand Up @@ -907,7 +907,7 @@ async def callback() -> None:
check=lambda i, c: c == command,
timeout=3,
)
except asyncio.TimeoutError:
except TimeoutError:
return
else:
if not autocomplete_task.done():
Expand Down
5 changes: 3 additions & 2 deletions discord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@
from typing import (
TYPE_CHECKING,
Any,
Self,
TypeVar,
)

import aiohttp
from typing_extensions import Self, deprecated
from typing_extensions import deprecated

from . import utils
from .activity import ActivityTypes, BaseActivity, create_activity
Expand Down Expand Up @@ -732,7 +733,7 @@ async def connect(self, *, reconnect: bool = True) -> None:
GatewayNotFound,
ConnectionClosed,
aiohttp.ClientError,
asyncio.TimeoutError,
TimeoutError,
) as exc:
self.dispatch("disconnect")
if not reconnect:
Expand Down
4 changes: 2 additions & 2 deletions discord/colour.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@

import colorsys
import random
from typing import Any
from typing import Any, Self

from typing_extensions import Self, deprecated, override
from typing_extensions import deprecated, override

__all__ = (
"Colour",
Expand Down
7 changes: 2 additions & 5 deletions discord/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@
Any,
Generic,
Literal,
Self,
TypeVar,
Union,
get_args,
get_origin,
)

from typing_extensions import Self

from ..channel import PartialMessageable, _threaded_guild_channel_factory
from ..enums import Enum as DiscordEnum
from ..enums import IntegrationType, InteractionContextType, SlashCommandOptionType
Expand Down Expand Up @@ -83,9 +82,7 @@
)

if TYPE_CHECKING:
from typing import Concatenate, ParamSpec

from typing_extensions import Never
from typing import Concatenate, Never, ParamSpec

from .. import Permissions
from ..bot import C
Expand Down
4 changes: 2 additions & 2 deletions discord/embeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,11 +1057,11 @@ def to_dict(self) -> EmbedData:
if timestamp:
if timestamp.tzinfo:
result["timestamp"] = timestamp.astimezone(
tz=datetime.timezone.utc
tz=datetime.UTC
).isoformat()
else:
result["timestamp"] = timestamp.replace(
tzinfo=datetime.timezone.utc
tzinfo=datetime.UTC
).isoformat()

# add in the non-raw attribute ones
Expand Down
6 changes: 3 additions & 3 deletions discord/ext/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ async def call_after_hooks(self, ctx: Context) -> None:
def _prepare_cooldowns(self, ctx: Context) -> None:
if self._buckets.valid:
dt = ctx.message.edited_at or ctx.message.created_at
current = dt.replace(tzinfo=datetime.timezone.utc).timestamp()
current = dt.replace(tzinfo=datetime.UTC).timestamp()
bucket = self._buckets.get_bucket(ctx.message, current)
if bucket is not None:
retry_after = bucket.update_rate_limit(current)
Expand Down Expand Up @@ -907,7 +907,7 @@ def is_on_cooldown(self, ctx: Context) -> bool:

bucket = self._buckets.get_bucket(ctx.message)
dt = ctx.message.edited_at or ctx.message.created_at
current = dt.replace(tzinfo=datetime.timezone.utc).timestamp()
current = dt.replace(tzinfo=datetime.UTC).timestamp()
return bucket.get_tokens(current) == 0

def reset_cooldown(self, ctx: Context) -> None:
Expand Down Expand Up @@ -941,7 +941,7 @@ def get_cooldown_retry_after(self, ctx: Context) -> float:
if self._buckets.valid:
bucket = self._buckets.get_bucket(ctx.message)
dt = ctx.message.edited_at or ctx.message.created_at
current = dt.replace(tzinfo=datetime.timezone.utc).timestamp()
current = dt.replace(tzinfo=datetime.UTC).timestamp()
return bucket.get_retry_after(current)

return 0.0
Expand Down
18 changes: 8 additions & 10 deletions discord/ext/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ async def _loop(self, *args: Any, **kwargs: Any) -> None:
self._prepare_time_index()
self._next_iteration = self._get_next_sleep_time()
else:
self._next_iteration = datetime.datetime.now(datetime.timezone.utc)
self._next_iteration = datetime.datetime.now(datetime.UTC)
try:
await self._try_sleep_until(self._next_iteration)
while True:
Expand Down Expand Up @@ -225,7 +225,7 @@ async def _loop(self, *args: Any, **kwargs: Any) -> None:
if self._stop_next_iteration:
return

now = datetime.datetime.now(datetime.timezone.utc)
now = datetime.datetime.now(datetime.UTC)
if now > self._next_iteration:
self._next_iteration = now
if self._time is not MISSING:
Expand Down Expand Up @@ -629,7 +629,7 @@ def _get_next_sleep_time(self) -> datetime.datetime:
if self._current_loop == 0:
# if we're at the last index on the first iteration, we need to sleep until tomorrow
return datetime.datetime.combine(
datetime.datetime.now(self._time[0].tzinfo or datetime.timezone.utc)
datetime.datetime.now(self._time[0].tzinfo or datetime.UTC)
+ datetime.timedelta(days=1),
self._time[0],
)
Expand All @@ -640,17 +640,15 @@ def _get_next_sleep_time(self) -> datetime.datetime:
self._time_index += 1
if (
next_time
> datetime.datetime.now(
next_time.tzinfo or datetime.timezone.utc
).timetz()
> datetime.datetime.now(next_time.tzinfo or datetime.UTC).timetz()
):
return datetime.datetime.combine(
datetime.datetime.now(next_time.tzinfo or datetime.timezone.utc),
datetime.datetime.now(next_time.tzinfo or datetime.UTC),
next_time,
)
else:
return datetime.datetime.combine(
datetime.datetime.now(next_time.tzinfo or datetime.timezone.utc)
datetime.datetime.now(next_time.tzinfo or datetime.UTC)
+ datetime.timedelta(days=1),
next_time,
)
Expand All @@ -672,7 +670,7 @@ def _prepare_time_index(self, now: datetime.datetime = MISSING) -> None:
time_now = (
now
if now is not MISSING
else datetime.datetime.now(datetime.timezone.utc).replace(microsecond=0)
else datetime.datetime.now(datetime.UTC).replace(microsecond=0)
)
for idx, time in enumerate(self._time):
if time >= time_now.astimezone(time.tzinfo).timetz():
Expand All @@ -686,7 +684,7 @@ def _get_time_parameter(
time: datetime.time | Sequence[datetime.time],
*,
dt: type[datetime.time] = datetime.time,
utc: datetime.timezone = datetime.timezone.utc,
utc: datetime.timezone = datetime.UTC,
) -> list[datetime.time]:
if isinstance(time, dt):
inner = time if time.tzinfo is not None else time.replace(tzinfo=utc)
Expand Down
4 changes: 2 additions & 2 deletions discord/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from .errors import ConnectionClosed, InvalidArgument

if TYPE_CHECKING:
from typing_extensions import Self
from typing import Self

from .client import Client
from .state import ConnectionState
Expand Down Expand Up @@ -646,7 +646,7 @@ async def poll_event(self) -> None:
):
_log.debug("Received %s", msg)
raise WebSocketClosure
except (asyncio.TimeoutError, WebSocketClosure) as e:
except (TimeoutError, WebSocketClosure) as e:
# Ensure the keep alive handler is closed
if self._keep_alive:
self._keep_alive.stop()
Expand Down
2 changes: 1 addition & 1 deletion discord/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ async def sync(self) -> None:
Syncing the integration failed.
"""
await self._state.http.sync_integration(self.guild.id, self.id)
self.synced_at = datetime.datetime.now(datetime.timezone.utc)
self.synced_at = datetime.datetime.now(datetime.UTC)


class IntegrationApplication:
Expand Down
2 changes: 1 addition & 1 deletion discord/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
from .utils import MISSING

if TYPE_CHECKING:
from typing_extensions import Self
from typing import Self

from .voice import VoiceClient

Expand Down
2 changes: 1 addition & 1 deletion discord/raw_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ def __init__(self, data: TypingEvent) -> None:
self.channel_id: int = int(data["channel_id"])
self.user_id: int = int(data["user_id"])
self.when: datetime.datetime = datetime.datetime.fromtimestamp(
data.get("timestamp"), tz=datetime.timezone.utc
data.get("timestamp"), tz=datetime.UTC
)
self.member: Member | None = None
self.guild_id: int | None = utils._get_as_snowflake(data, "guild_id")
Expand Down
4 changes: 2 additions & 2 deletions discord/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
from __future__ import annotations

from contextlib import suppress
from typing import TYPE_CHECKING, Any, TypeVar
from typing import TYPE_CHECKING, Any, Self, TypeVar

from typing_extensions import Self, deprecated
from typing_extensions import deprecated

from .asset import Asset
from .colour import Colour
Expand Down
14 changes: 7 additions & 7 deletions discord/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ async def query_members(
nonce=request.nonce,
)
return await asyncio.wait_for(request.wait(), timeout=30.0)
except asyncio.TimeoutError:
except TimeoutError:
_log.warning(
(
"Timed out waiting for chunks with query %r and limit %d for"
Expand Down Expand Up @@ -645,7 +645,7 @@ async def _delay_ready(self) -> None:
guild = await asyncio.wait_for(
self._ready_state.get(), timeout=self.guild_ready_timeout
)
except asyncio.TimeoutError:
except TimeoutError:
break
else:
if self._guild_needs_chunking(guild):
Expand All @@ -659,7 +659,7 @@ async def _delay_ready(self) -> None:
for guild, future in states:
try:
await asyncio.wait_for(future, timeout=5.0)
except asyncio.TimeoutError:
except TimeoutError:
_log.warning(
"Shard ID %s timed out waiting for chunks for guild_id %s.",
guild.shard_id,
Expand Down Expand Up @@ -1460,7 +1460,7 @@ async def chunk_guild(self, guild, *, wait=True, cache=None):
async def _chunk_and_dispatch(self, guild, unavailable):
try:
await asyncio.wait_for(self.chunk_guild(guild), timeout=60.0)
except asyncio.TimeoutError:
except TimeoutError:
_log.info("Somehow timed out waiting for chunks.")

if unavailable is False:
Expand Down Expand Up @@ -2188,7 +2188,7 @@ async def _delay_ready(self) -> None:
guild = await asyncio.wait_for(
self._ready_state.get(), timeout=self.guild_ready_timeout
)
except asyncio.TimeoutError:
except TimeoutError:
break
else:
if self._guild_needs_chunking(guild):
Expand All @@ -2204,7 +2204,7 @@ async def _delay_ready(self) -> None:
await utils.sane_wait_for(
current_bucket, timeout=max_concurrency * 70.0
)
except asyncio.TimeoutError:
except TimeoutError:
fmt = (
"Shard ID %s failed to wait for chunks from a"
" sub-bucket with length %d"
Expand All @@ -2229,7 +2229,7 @@ async def _delay_ready(self) -> None:
timeout = 61 * (len(children) / 110)
try:
await utils.sane_wait_for(futures, timeout=timeout)
except asyncio.TimeoutError:
except TimeoutError:
_log.warning(
(
"Shard ID %s failed to wait for chunks (timeout=%.2f) for %d"
Expand Down
Loading
Loading