Reformat entire project with ruff instead of black

This commit is contained in:
Rapptz
2025-08-18 20:15:44 -04:00
parent 3ef6272e07
commit 44a44e938f
88 changed files with 485 additions and 730 deletions

View File

@ -22,7 +22,6 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
from typing import Any, Awaitable, Callable, Coroutine, TYPE_CHECKING, Protocol, TypeVar, Union, Tuple, Optional
@ -49,9 +48,9 @@ MaybeCoro = Union[T, Coro[T]]
MaybeAwaitable = Union[T, Awaitable[T]]
CogT = TypeVar('CogT', bound='Optional[Cog]')
UserCheck = Callable[["ContextT"], MaybeCoro[bool]]
Hook = Union[Callable[["CogT", "ContextT"], Coro[Any]], Callable[["ContextT"], Coro[Any]]]
Error = Union[Callable[["CogT", "ContextT", "CommandError"], Coro[Any]], Callable[["ContextT", "CommandError"], Coro[Any]]]
UserCheck = Callable[['ContextT'], MaybeCoro[bool]]
Hook = Union[Callable[['CogT', 'ContextT'], Coro[Any]], Callable[['ContextT'], Coro[Any]]]
Error = Union[Callable[['CogT', 'ContextT', 'CommandError'], Coro[Any]], Callable[['ContextT', 'CommandError'], Coro[Any]]]
ContextT = TypeVar('ContextT', bound='Context[Any]')
BotT = TypeVar('BotT', bound=_Bot, covariant=True)
@ -60,11 +59,9 @@ ContextT_co = TypeVar('ContextT_co', bound='Context[Any]', covariant=True)
class Check(Protocol[ContextT_co]): # type: ignore # TypeVar is expected to be invariant
predicate: Callable[[ContextT_co], Coroutine[Any, Any, bool]]
def __call__(self, coro_or_commands: T) -> T:
...
def __call__(self, coro_or_commands: T) -> T: ...
# This is merely a tag type to avoid circular import issues.

View File

@ -94,8 +94,7 @@ if TYPE_CHECKING:
strip_after_prefix: bool
case_insensitive: bool
class _AutoShardedBotOptions(_AutoShardedClientOptions, _BotOptions):
...
class _AutoShardedBotOptions(_AutoShardedClientOptions, _BotOptions): ...
__all__ = (
@ -1233,8 +1232,8 @@ class BotBase(GroupMixin[None]):
raise
raise TypeError(
"command_prefix must be plain string, iterable of strings, or callable "
f"returning either of these, not {ret.__class__.__name__}"
'command_prefix must be plain string, iterable of strings, or callable '
f'returning either of these, not {ret.__class__.__name__}'
)
return ret
@ -1254,8 +1253,7 @@ class BotBase(GroupMixin[None]):
/,
*,
cls: Type[ContextT],
) -> ContextT:
...
) -> ContextT: ...
async def get_context(
self,
@ -1332,15 +1330,15 @@ class BotBase(GroupMixin[None]):
except TypeError:
if not isinstance(prefix, list):
raise TypeError(
"get_prefix must return either a string or a list of string, " f"not {prefix.__class__.__name__}"
f'get_prefix must return either a string or a list of string, not {prefix.__class__.__name__}'
)
# It's possible a bad command_prefix got us here.
for value in prefix:
if not isinstance(value, str):
raise TypeError(
"Iterable command_prefix or list returned from get_prefix must "
f"contain only strings, not {value.__class__.__name__}"
'Iterable command_prefix or list returned from get_prefix must '
f'contain only strings, not {value.__class__.__name__}'
)
# Getting here shouldn't happen
@ -1552,5 +1550,4 @@ class AutoShardedBot(BotBase, discord.AutoShardedClient):
allowed_installs: app_commands.AppInstallationType = MISSING,
intents: discord.Intents,
**kwargs: Unpack[_AutoShardedBotOptions],
) -> None:
...
) -> None: ...

View File

@ -21,6 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
from __future__ import annotations
import inspect

View File

@ -21,6 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
from __future__ import annotations
import re
@ -70,7 +71,7 @@ MISSING: Any = discord.utils.MISSING
T = TypeVar('T')
CogT = TypeVar('CogT', bound="Cog")
CogT = TypeVar('CogT', bound='Cog')
if TYPE_CHECKING:
P = ParamSpec('P')
@ -424,8 +425,8 @@ class Context(discord.abc.Messageable, Generic[BotT]):
# consider this to be an *incredibly* strange use case. I'd rather go
# for this common use case rather than waste performance for the
# odd one.
pattern = re.compile(r"<@!?%s>" % user.id)
return pattern.sub("@%s" % user.display_name.replace('\\', r'\\'), self.prefix)
pattern = re.compile(r'<@!?%s>' % user.id)
return pattern.sub('@%s' % user.display_name.replace('\\', r'\\'), self.prefix)
@property
def cog(self) -> Optional[Cog]:
@ -642,8 +643,7 @@ class Context(discord.abc.Messageable, Generic[BotT]):
suppress_embeds: bool = ...,
ephemeral: bool = ...,
silent: bool = ...,
) -> Message:
...
) -> Message: ...
@overload
async def reply(
@ -659,8 +659,7 @@ class Context(discord.abc.Messageable, Generic[BotT]):
suppress_embeds: bool = ...,
ephemeral: bool = ...,
silent: bool = ...,
) -> Message:
...
) -> Message: ...
@overload
async def reply(
@ -681,8 +680,7 @@ class Context(discord.abc.Messageable, Generic[BotT]):
ephemeral: bool = ...,
silent: bool = ...,
poll: Poll = ...,
) -> Message:
...
) -> Message: ...
@overload
async def reply(
@ -703,8 +701,7 @@ class Context(discord.abc.Messageable, Generic[BotT]):
ephemeral: bool = ...,
silent: bool = ...,
poll: Poll = ...,
) -> Message:
...
) -> Message: ...
@overload
async def reply(
@ -725,8 +722,7 @@ class Context(discord.abc.Messageable, Generic[BotT]):
ephemeral: bool = ...,
silent: bool = ...,
poll: Poll = ...,
) -> Message:
...
) -> Message: ...
@overload
async def reply(
@ -747,8 +743,7 @@ class Context(discord.abc.Messageable, Generic[BotT]):
ephemeral: bool = ...,
silent: bool = ...,
poll: Poll = ...,
) -> Message:
...
) -> Message: ...
async def reply(self, content: Optional[str] = None, **kwargs: Any) -> Message:
"""|coro|
@ -865,8 +860,7 @@ class Context(discord.abc.Messageable, Generic[BotT]):
suppress_embeds: bool = ...,
ephemeral: bool = ...,
silent: bool = ...,
) -> Message:
...
) -> Message: ...
@overload
async def send(
@ -882,8 +876,7 @@ class Context(discord.abc.Messageable, Generic[BotT]):
suppress_embeds: bool = ...,
ephemeral: bool = ...,
silent: bool = ...,
) -> Message:
...
) -> Message: ...
@overload
async def send(
@ -904,8 +897,7 @@ class Context(discord.abc.Messageable, Generic[BotT]):
ephemeral: bool = ...,
silent: bool = ...,
poll: Poll = ...,
) -> Message:
...
) -> Message: ...
@overload
async def send(
@ -926,8 +918,7 @@ class Context(discord.abc.Messageable, Generic[BotT]):
ephemeral: bool = ...,
silent: bool = ...,
poll: Poll = ...,
) -> Message:
...
) -> Message: ...
@overload
async def send(
@ -948,8 +939,7 @@ class Context(discord.abc.Messageable, Generic[BotT]):
ephemeral: bool = ...,
silent: bool = ...,
poll: Poll = ...,
) -> Message:
...
) -> Message: ...
@overload
async def send(
@ -970,8 +960,7 @@ class Context(discord.abc.Messageable, Generic[BotT]):
ephemeral: bool = ...,
silent: bool = ...,
poll: Poll = ...,
) -> Message:
...
) -> Message: ...
async def send(
self,

View File

@ -1347,13 +1347,11 @@ async def _actual_conversion(ctx: Context[BotT], converter: Any, argument: str,
@overload
async def run_converters(
ctx: Context[BotT], converter: Union[Type[Converter[T]], Converter[T]], argument: str, param: Parameter
) -> T:
...
) -> T: ...
@overload
async def run_converters(ctx: Context[BotT], converter: Any, argument: str, param: Parameter) -> Any:
...
async def run_converters(ctx: Context[BotT], converter: Any, argument: str, param: Parameter) -> Any: ...
async def run_converters(ctx: Context[BotT], converter: Any, argument: str, param: Parameter) -> Any:

View File

@ -242,10 +242,10 @@ class MaxConcurrency:
self.wait: bool = wait
if number <= 0:
raise ValueError('max_concurrency \'number\' cannot be less than 1')
raise ValueError("max_concurrency 'number' cannot be less than 1")
if not isinstance(per, BucketType):
raise TypeError(f'max_concurrency \'per\' must be of type BucketType not {type(per)!r}')
raise TypeError(f"max_concurrency 'per' must be of type BucketType not {type(per)!r}")
def copy(self) -> Self:
return self.__class__(self.number, per=self.per, wait=self.wait)

View File

@ -21,6 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
from __future__ import annotations
import asyncio
@ -398,6 +399,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
.. versionadded:: 2.0
"""
__original_kwargs__: Dict[str, Any]
def __new__(cls, *args: Any, **kwargs: Any) -> Self:
@ -451,7 +453,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
self.extras: Dict[Any, Any] = kwargs.get('extras', {})
if not isinstance(self.aliases, (list, tuple)):
raise TypeError("Aliases of a command must be a list or a tuple of strings.")
raise TypeError('Aliases of a command must be a list or a tuple of strings.')
self.description: str = inspect.cleandoc(kwargs.get('description', ''))
self.hidden: bool = kwargs.get('hidden', False)
@ -474,7 +476,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
elif isinstance(cooldown, CooldownMapping):
buckets: CooldownMapping[Context[Any]] = cooldown
else:
raise TypeError("Cooldown must be an instance of CooldownMapping or None.")
raise TypeError('Cooldown must be an instance of CooldownMapping or None.')
self._buckets: CooldownMapping[Context[Any]] = buckets
try:
@ -520,7 +522,10 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
@property
def callback(
self,
) -> Union[Callable[Concatenate[CogT, Context[Any], P], Coro[T]], Callable[Concatenate[Context[Any], P], Coro[T]],]:
) -> Union[
Callable[Concatenate[CogT, Context[Any], P], Coro[T]],
Callable[Concatenate[Context[Any], P], Coro[T]],
]:
return self._callback
@callback.setter
@ -1507,8 +1512,7 @@ class GroupMixin(Generic[CogT]):
]
],
Command[CogT, P, T],
]:
...
]: ...
@overload
def command(
@ -1525,8 +1529,7 @@ class GroupMixin(Generic[CogT]):
]
],
CommandT,
]:
...
]: ...
def command(
self,
@ -1566,8 +1569,7 @@ class GroupMixin(Generic[CogT]):
]
],
Group[CogT, P, T],
]:
...
]: ...
@overload
def group(
@ -1584,8 +1586,7 @@ class GroupMixin(Generic[CogT]):
]
],
GroupT,
]:
...
]: ...
def group(
self,
@ -1731,35 +1732,28 @@ if TYPE_CHECKING:
class _CommandDecorator:
@overload
def __call__(self, func: Callable[Concatenate[CogT, ContextT, P], Coro[T]], /) -> Command[CogT, P, T]:
...
def __call__(self, func: Callable[Concatenate[CogT, ContextT, P], Coro[T]], /) -> Command[CogT, P, T]: ...
@overload
def __call__(self, func: Callable[Concatenate[ContextT, P], Coro[T]], /) -> Command[None, P, T]:
...
def __call__(self, func: Callable[Concatenate[ContextT, P], Coro[T]], /) -> Command[None, P, T]: ...
def __call__(self, func: Callable[..., Coro[T]], /) -> Any:
...
def __call__(self, func: Callable[..., Coro[T]], /) -> Any: ...
class _GroupDecorator:
@overload
def __call__(self, func: Callable[Concatenate[CogT, ContextT, P], Coro[T]], /) -> Group[CogT, P, T]:
...
def __call__(self, func: Callable[Concatenate[CogT, ContextT, P], Coro[T]], /) -> Group[CogT, P, T]: ...
@overload
def __call__(self, func: Callable[Concatenate[ContextT, P], Coro[T]], /) -> Group[None, P, T]:
...
def __call__(self, func: Callable[Concatenate[ContextT, P], Coro[T]], /) -> Group[None, P, T]: ...
def __call__(self, func: Callable[..., Coro[T]], /) -> Any:
...
def __call__(self, func: Callable[..., Coro[T]], /) -> Any: ...
@overload
def command(
name: str = ...,
**attrs: Unpack[_CommandDecoratorKwargs],
) -> _CommandDecorator:
...
) -> _CommandDecorator: ...
@overload
@ -1775,8 +1769,7 @@ def command(
]
],
CommandT,
]:
...
]: ...
def command(
@ -1828,8 +1821,7 @@ def command(
def group(
name: str = ...,
**attrs: Unpack[_GroupDecoratorKwargs],
) -> _GroupDecorator:
...
) -> _GroupDecorator: ...
@overload
@ -1845,8 +1837,7 @@ def group(
]
],
GroupT,
]:
...
]: ...
def group(
@ -2226,7 +2217,7 @@ def has_permissions(**perms: Unpack[_PermissionsKwargs]) -> Check[Any]:
invalid = set(perms) - set(discord.Permissions.VALID_FLAGS)
if invalid:
raise TypeError(f"Invalid permission(s): {', '.join(invalid)}")
raise TypeError(f'Invalid permission(s): {", ".join(invalid)}')
def predicate(ctx: Context[BotT]) -> bool:
permissions = ctx.permissions
@ -2251,7 +2242,7 @@ def bot_has_permissions(**perms: Unpack[_PermissionsKwargs]) -> Check[Any]:
invalid = set(perms) - set(discord.Permissions.VALID_FLAGS)
if invalid:
raise TypeError(f"Invalid permission(s): {', '.join(invalid)}")
raise TypeError(f'Invalid permission(s): {", ".join(invalid)}')
def predicate(ctx: Context[BotT]) -> bool:
permissions = ctx.bot_permissions
@ -2278,7 +2269,7 @@ def has_guild_permissions(**perms: Unpack[_PermissionsKwargs]) -> Check[Any]:
invalid = set(perms) - set(discord.Permissions.VALID_FLAGS)
if invalid:
raise TypeError(f"Invalid permission(s): {', '.join(invalid)}")
raise TypeError(f'Invalid permission(s): {", ".join(invalid)}')
def predicate(ctx: Context[BotT]) -> bool:
if not ctx.guild:
@ -2304,7 +2295,7 @@ def bot_has_guild_permissions(**perms: Unpack[_PermissionsKwargs]) -> Check[Any]
invalid = set(perms) - set(discord.Permissions.VALID_FLAGS)
if invalid:
raise TypeError(f"Invalid permission(s): {', '.join(invalid)}")
raise TypeError(f'Invalid permission(s): {", ".join(invalid)}')
def predicate(ctx: Context[BotT]) -> bool:
if not ctx.guild:
@ -2544,7 +2535,7 @@ def dynamic_cooldown(
The type of cooldown to have.
"""
if not callable(cooldown):
raise TypeError("A callable must be provided")
raise TypeError('A callable must be provided')
if type is BucketType.default:
raise ValueError('BucketType.default cannot be used in dynamic cooldowns')

View File

@ -925,7 +925,7 @@ class BadLiteralArgument(UserInputError):
.. versionadded:: 2.3
"""
def __init__(self, param: Parameter, literals: Tuple[Any, ...], errors: List[CommandError], argument: str = "") -> None:
def __init__(self, param: Parameter, literals: Tuple[Any, ...], errors: List[CommandError], argument: str = '') -> None:
self.param: Parameter = param
self.literals: Tuple[Any, ...] = literals
self.errors: List[CommandError] = errors

View File

@ -197,7 +197,7 @@ def get_flags(namespace: Dict[str, Any], globals: Dict[str, Any], locals: Dict[s
if flag.positional:
if positional is not None:
raise TypeError(f"{flag.name!r} positional flag conflicts with {positional.name!r} flag.")
raise TypeError(f'{flag.name!r} positional flag conflicts with {positional.name!r} flag.')
positional = flag
annotation = flag.annotation = resolve_annotation(flag.annotation, globals, locals, cache)

View File

@ -1072,7 +1072,7 @@ class DefaultHelpCommand(HelpCommand):
self.sort_commands: bool = options.pop('sort_commands', True)
self.dm_help: bool = options.pop('dm_help', False)
self.dm_help_threshold: int = options.pop('dm_help_threshold', 1000)
self.arguments_heading: str = options.pop('arguments_heading', "Arguments:")
self.arguments_heading: str = options.pop('arguments_heading', 'Arguments:')
self.commands_heading: str = options.pop('commands_heading', 'Commands:')
self.default_argument_description: str = options.pop('default_argument_description', 'No description given')
self.no_category: str = options.pop('no_category', 'No Category')

View File

@ -278,8 +278,7 @@ class ParameterAlias(Protocol):
description: str = empty,
displayed_default: str = empty,
displayed_name: str = empty,
) -> Any:
...
) -> Any: ...
param: ParameterAlias = parameter

View File

@ -31,22 +31,22 @@ from .errors import UnexpectedQuoteError, InvalidEndOfQuotedStringError, Expecte
# map from opening quotes to closing quotes
_quotes = {
'"': '"',
"": "",
"": "",
"": "",
"": "",
"": "",
"": "",
"": "",
"": "",
"": "",
"": "",
"": "",
"": "",
"«": "»",
"": "",
"": "",
"": "",
'': '',
'': '',
'': '',
'': '',
'': '',
'': '',
'': '',
'': '',
'': '',
'': '',
'': '',
'': '',
'«': '»',
'': '',
'': '',
'': '',
}
_all_quotes = set(_quotes.keys()) | set(_quotes.values())