Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions changelog/1396.misc.rst
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

X | Y is 3.10 syntax, not 3.9

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Truth truth. This changelog is intended for a different pull request.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update all type hints across the source code to use PEP 604 style (``A | B`` instead of ``Union[A, B]``, and ``A | None`` instead of ``Optional[A]``).
6 changes: 3 additions & 3 deletions disnake/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import platform
import sys
from pathlib import Path
from typing import List, Tuple, Union
from typing import Union

import aiohttp

import disnake


def show_version() -> None:
entries: List[str] = []
entries: list[str] = []

sys_ver = sys.version_info
entries.append(
Expand Down Expand Up @@ -399,7 +399,7 @@ def add_newcog_args(subparser) -> None:
parser.add_argument("--full", help="add all special methods as well", action="store_true")


def parse_args() -> Tuple[argparse.ArgumentParser, argparse.Namespace]:
def parse_args() -> tuple[argparse.ArgumentParser, argparse.Namespace]:
parser = argparse.ArgumentParser(prog="disnake", description="Tools for helping with disnake")
parser.add_argument("-v", "--version", action="store_true", help="shows the library version")
parser.set_defaults(func=core)
Expand Down
52 changes: 24 additions & 28 deletions disnake/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
import asyncio
import copy
from abc import ABC
from collections.abc import Mapping, Sequence
from typing import (
TYPE_CHECKING,
Any,
Callable,
Dict,
List,
Mapping,
Optional,
Protocol,
Sequence,
Tuple,
TypeVar,
Union,
cast,
Expand Down Expand Up @@ -264,7 +260,7 @@ class GuildChannel(ABC):
category_id: Optional[int]
_flags: int
_state: ConnectionState
_overwrites: List[_Overwrites]
_overwrites: list[_Overwrites]

if TYPE_CHECKING:

Expand All @@ -279,7 +275,7 @@ def __str__(self) -> str:
def _sorting_bucket(self) -> int:
raise NotImplementedError

def _update(self, guild: Guild, data: Dict[str, Any]) -> None:
def _update(self, guild: Guild, data: dict[str, Any]) -> None:
raise NotImplementedError

async def _move(
Expand All @@ -297,7 +293,7 @@ async def _move(
http = self._state.http
bucket = self._sorting_bucket
channels = [c for c in self.guild.channels if c._sorting_bucket == bucket]
channels = cast("List[GuildChannel]", channels)
channels = cast("list[GuildChannel]", channels)

channels.sort(key=lambda c: c.position)

Expand All @@ -314,7 +310,7 @@ async def _move(
# add ourselves at our designated position
channels.insert(index, self)

payload: List[ChannelPositionUpdatePayload] = []
payload: list[ChannelPositionUpdatePayload] = []
for index, c in enumerate(channels):
d: ChannelPositionUpdatePayload = {"id": c.id, "position": index}
if parent_id is not MISSING and c.id == self.id:
Expand Down Expand Up @@ -380,7 +376,7 @@ async def _edit(

lock_permissions: bool = bool(sync_permissions)

overwrites_payload: List[PermissionOverwritePayload] = MISSING
overwrites_payload: list[PermissionOverwritePayload] = MISSING

if position is not MISSING:
await self._move(
Expand Down Expand Up @@ -430,7 +426,7 @@ async def _edit(
else:
flags_payload = MISSING

available_tags_payload: List[PartialForumTagPayload] = MISSING
available_tags_payload: list[PartialForumTagPayload] = MISSING
if available_tags is not MISSING:
available_tags_payload = [tag.to_dict() for tag in available_tags]

Expand All @@ -455,7 +451,7 @@ async def _edit(
if default_layout is not MISSING:
default_layout_payload = try_enum_to_int(default_layout)

options: Dict[str, Any] = {
options: dict[str, Any] = {
"name": name,
"parent_id": parent_id,
"topic": topic,
Expand Down Expand Up @@ -507,11 +503,11 @@ def _fill_overwrites(self, data: GuildChannelPayload) -> None:
tmp[everyone_index], tmp[0] = tmp[0], tmp[everyone_index]

@property
def changed_roles(self) -> List[Role]:
def changed_roles(self) -> list[Role]:
""":class:`list`\\[:class:`.Role`]: Returns a list of roles that have been overridden from
their default values in the :attr:`.Guild.roles` attribute.
"""
ret: List[Role] = []
ret: list[Role] = []
g = self.guild
for overwrite in filter(lambda o: o.is_role(), self._overwrites):
role = g.get_role(overwrite.id)
Expand Down Expand Up @@ -564,7 +560,7 @@ def overwrites_for(self, obj: Union[Role, User]) -> PermissionOverwrite:
return PermissionOverwrite()

@property
def overwrites(self) -> Dict[Union[Role, Member], PermissionOverwrite]:
def overwrites(self) -> dict[Union[Role, Member], PermissionOverwrite]:
"""Returns all of the channel's overwrites.
This is returned as a dictionary where the key contains the target which
Expand Down Expand Up @@ -1043,7 +1039,7 @@ async def set_permissions(

async def _clone_impl(
self,
base_attrs: Dict[str, Any],
base_attrs: dict[str, Any],
*,
name: Optional[str] = None,
category: Optional[Snowflake] = MISSING,
Expand All @@ -1052,7 +1048,7 @@ async def _clone_impl(
) -> Self:
# if the overwrites are MISSING, defaults to the
# original permissions of the channel
overwrites_payload: List[PermissionOverwritePayload]
overwrites_payload: list[PermissionOverwritePayload]
if overwrites is not MISSING:
if not isinstance(overwrites, dict):
msg = "overwrites parameter expects a dict."
Expand Down Expand Up @@ -1259,7 +1255,7 @@ async def move(self, **kwargs: Any) -> None:
]

channels.sort(key=lambda c: (c.position, c.id))
channels = cast("List[GuildChannel]", channels)
channels = cast("list[GuildChannel]", channels)

try:
# Try to remove ourselves from the channel list
Expand All @@ -1283,7 +1279,7 @@ async def move(self, **kwargs: Any) -> None:
raise ValueError(msg)

channels.insert(max((index + offset), 0), self)
payload: List[ChannelPositionUpdatePayload] = []
payload: list[ChannelPositionUpdatePayload] = []
lock_permissions = kwargs.get("sync_permissions", False)
reason = kwargs.get("reason")
for index, channel in enumerate(channels):
Expand Down Expand Up @@ -1389,7 +1385,7 @@ async def create_invite(
invite.guild_scheduled_event = guild_scheduled_event
return invite

async def invites(self) -> List[Invite]:
async def invites(self) -> list[Invite]:
"""|coro|
Returns a list of all active instant invites from this channel.
Expand Down Expand Up @@ -1465,7 +1461,7 @@ async def send(
*,
tts: bool = ...,
embed: Embed = ...,
files: List[File] = ...,
files: list[File] = ...,
stickers: Sequence[Union[GuildSticker, StandardSticker, StickerItem]] = ...,
delete_after: float = ...,
nonce: Union[str, int] = ...,
Expand All @@ -1485,7 +1481,7 @@ async def send(
content: Optional[str] = ...,
*,
tts: bool = ...,
embeds: List[Embed] = ...,
embeds: list[Embed] = ...,
file: File = ...,
stickers: Sequence[Union[GuildSticker, StandardSticker, StickerItem]] = ...,
delete_after: float = ...,
Expand All @@ -1506,8 +1502,8 @@ async def send(
content: Optional[str] = ...,
*,
tts: bool = ...,
embeds: List[Embed] = ...,
files: List[File] = ...,
embeds: list[Embed] = ...,
files: list[File] = ...,
stickers: Sequence[Union[GuildSticker, StandardSticker, StickerItem]] = ...,
delete_after: float = ...,
nonce: Union[str, int] = ...,
Expand All @@ -1527,9 +1523,9 @@ async def send(
*,
tts: bool = False,
embed: Optional[Embed] = None,
embeds: Optional[List[Embed]] = None,
embeds: Optional[list[Embed]] = None,
file: Optional[File] = None,
files: Optional[List[File]] = None,
files: Optional[list[File]] = None,
stickers: Optional[Sequence[Union[GuildSticker, StandardSticker, StickerItem]]] = None,
delete_after: Optional[float] = None,
nonce: Optional[Union[str, int]] = None,
Expand Down Expand Up @@ -2033,10 +2029,10 @@ class Connectable(Protocol):
guild: Guild
id: int

def _get_voice_client_key(self) -> Tuple[int, str]:
def _get_voice_client_key(self) -> tuple[int, str]:
raise NotImplementedError

def _get_voice_state_pair(self) -> Tuple[int, int]:
def _get_voice_state_pair(self) -> tuple[int, int]:
raise NotImplementedError

async def connect(
Expand Down
18 changes: 9 additions & 9 deletions disnake/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

import datetime
from typing import TYPE_CHECKING, Any, Dict, List, Literal, Optional, Union, overload
from typing import TYPE_CHECKING, Any, Literal, Optional, Union, overload

from .asset import Asset
from .colour import Colour
Expand Down Expand Up @@ -339,7 +339,7 @@ def __init__(
party: Optional[ActivityParty] = None,
application_id: Optional[Union[str, int]] = None,
flags: Optional[int] = None,
buttons: Optional[List[str]] = None,
buttons: Optional[list[str]] = None,
emoji: Optional[Union[PartialEmojiPayload, ActivityEmojiPayload]] = None,
id: Optional[str] = None,
platform: Optional[str] = None,
Expand All @@ -360,7 +360,7 @@ def __init__(
self.name: Optional[str] = name
self.url: Optional[str] = url
self.flags: int = flags or 0
self.buttons: List[str] = buttons or []
self.buttons: list[str] = buttons or []

# undocumented fields:
self.id: Optional[str] = id
Expand Down Expand Up @@ -398,8 +398,8 @@ def __repr__(self) -> str:
inner = " ".join(f"{k!s}={v!r}" for k, v in attrs)
return f"<Activity {inner}>"

def to_dict(self) -> Dict[str, Any]:
ret: Dict[str, Any] = {}
def to_dict(self) -> dict[str, Any]:
ret: dict[str, Any] = {}
for attr in self.__slots__:
value = getattr(self, attr, None)
if value is None:
Expand Down Expand Up @@ -608,8 +608,8 @@ def twitch_name(self) -> Optional[str]:
name = self.assets["large_image"]
return name[7:] if name[:7] == "twitch:" else None

def to_dict(self) -> Dict[str, Any]:
ret: Dict[str, Any] = {
def to_dict(self) -> dict[str, Any]:
ret: dict[str, Any] = {
"type": ActivityType.streaming.value,
"name": str(self.name),
"url": str(self.url),
Expand Down Expand Up @@ -700,7 +700,7 @@ def color(self) -> Colour:
"""
return self.colour

def to_dict(self) -> Dict[str, Any]:
def to_dict(self) -> dict[str, Any]:
return {
"flags": 48, # SYNC | PLAY
"name": "Spotify",
Expand Down Expand Up @@ -744,7 +744,7 @@ def title(self) -> str:
return self._details

@property
def artists(self) -> List[str]:
def artists(self) -> list[str]:
""":class:`list`\\[:class:`str`]: The artists of the song being played."""
return self._state.split("; ")

Expand Down
Loading