Skip to content

Commit

Permalink
chore: fix new ruff complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
tandemdude committed Dec 6, 2024
1 parent c690a9c commit 6bcac87
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 33 deletions.
4 changes: 2 additions & 2 deletions lightbulb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def error_handler(
sorted_handlers = sorted(self._error_handlers.items(), key=lambda item: item[0], reverse=True)
self._error_handlers = {k: v for k, v in sorted_handlers}

return t.cast(ErrorHandlerT, wrapped)
return t.cast("ErrorHandlerT", wrapped)

def _inner(func_: ErrorHandlerT) -> ErrorHandlerT:
return self.error_handler(func_, priority=priority)
Expand All @@ -447,7 +447,7 @@ def remove_error_handler(self, func: lb_types.ErrorHandler) -> None:
h for h in handlers if h is not func and (isinstance(h, di_.AutoInjecting) and h._func is not func)
]
if handlers:
new_handlers[priority] = t.cast(list[lb_types.ErrorHandler], handlers)
new_handlers[priority] = t.cast("list[lb_types.ErrorHandler]", handlers)

sorted_handlers = sorted(new_handlers.items(), key=lambda item: item[0], reverse=True)
self._error_handlers = {k: v for k, v in sorted_handlers}
Expand Down
12 changes: 6 additions & 6 deletions lightbulb/commands/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def __new__(cls, cls_name: str, bases: tuple[type, ...], attrs: dict[str, t.Any]

# Don't want to use a set for deduplicating because we want to preserve ordering
hooks: list[t.Any] = []
for hook in t.cast(Iterable[t.Any], raw_hooks or []):
for hook in t.cast("Iterable[t.Any]", raw_hooks or []):
if hook in hooks:
continue
hooks.append(hook)
Expand Down Expand Up @@ -353,7 +353,7 @@ def _resolve_option(self, option: options_.Option[T, D]) -> T | D:
raise RuntimeError("cannot resolve option if no context is available")

if option._data._localized_name in self._resolved_option_cache:
return t.cast(T, self._resolved_option_cache[option._data._localized_name])
return t.cast("T", self._resolved_option_cache[option._data._localized_name])

found = [opt for opt in context.options if opt.name == option._data._localized_name]

Expand All @@ -366,7 +366,7 @@ def _resolve_option(self, option: options_.Option[T, D]) -> T | D:

if option._data.type in _PRIMITIVE_OPTION_TYPES:
self._resolved_option_cache[option._data._localized_name] = found[0].value
return t.cast(T, found[0].value)
return t.cast("T", found[0].value)

snowflake = found[0].value
resolved = context.interaction.resolved
Expand All @@ -388,7 +388,7 @@ def _resolve_option(self, option: options_.Option[T, D]) -> T | D:
raise TypeError("unsupported option type passed")

self._resolved_option_cache[option._data._localized_name] = resolved_option
return t.cast(T, resolved_option)
return t.cast("T", resolved_option)

@classmethod
async def as_command_builder(
Expand Down Expand Up @@ -487,7 +487,7 @@ async def invoke(self, ctx: lightbulb.Context):

__slots__ = ()

target: hikari.User = t.cast(hikari.User, options_.ContextMenuOption(hikari.User))
target: hikari.User = t.cast("hikari.User", options_.ContextMenuOption(hikari.User))
"""The target user that the context menu command was executed on."""


Expand Down Expand Up @@ -526,5 +526,5 @@ async def invoke(self, ctx: lightbulb.Context):

__slots__ = ()

target: hikari.Message = t.cast(hikari.Message, options_.ContextMenuOption(hikari.Message))
target: hikari.Message = t.cast("hikari.Message", options_.ContextMenuOption(hikari.Message))
"""The target message that the context menu command was executed on."""
2 changes: 1 addition & 1 deletion lightbulb/commands/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class Example(
command._command_data.parent = self # type: ignore[reportGeneralTypeIssues]
return command

def _inner(_command: CommandT) -> CommandT:
def _inner(_command: CommandT) -> CommandT: # noqa: RUF052
return self.register(_command)

return _inner
Expand Down
18 changes: 9 additions & 9 deletions lightbulb/commands/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def string(
Descriptor allowing access to the option value from within a command invocation.
"""
return t.cast(
str,
"str",
Option(
OptionData(
type=hikari.OptionType.STRING,
Expand Down Expand Up @@ -372,7 +372,7 @@ def integer(
Descriptor allowing access to the option value from within a command invocation.
"""
return t.cast(
int,
"int",
Option(
OptionData(
type=hikari.OptionType.INTEGER,
Expand Down Expand Up @@ -414,7 +414,7 @@ def boolean(
Descriptor allowing access to the option value from within a command invocation.
"""
return t.cast(
bool,
"bool",
Option(
OptionData(
type=hikari.OptionType.BOOLEAN,
Expand Down Expand Up @@ -459,7 +459,7 @@ def number(
Descriptor allowing access to the option value from within a command invocation.
"""
return t.cast(
float,
"float",
Option(
OptionData(
type=hikari.OptionType.FLOAT,
Expand Down Expand Up @@ -501,7 +501,7 @@ def user(
Descriptor allowing access to the option value from within a command invocation.
"""
return t.cast(
hikari.User,
"hikari.User",
Option(
OptionData(
type=hikari.OptionType.USER,
Expand Down Expand Up @@ -540,7 +540,7 @@ def channel(
Descriptor allowing access to the option value from within a command invocation.
"""
return t.cast(
hikari.PartialChannel,
"hikari.PartialChannel",
Option(
OptionData(
type=hikari.OptionType.CHANNEL,
Expand Down Expand Up @@ -578,7 +578,7 @@ def role(
Descriptor allowing access to the option value from within a command invocation.
"""
return t.cast(
hikari.Role,
"hikari.Role",
Option(
OptionData(
type=hikari.OptionType.ROLE,
Expand Down Expand Up @@ -615,7 +615,7 @@ def mentionable(
Descriptor allowing access to the option value from within a command invocation.
"""
return t.cast(
hikari.Snowflake,
"hikari.Snowflake",
Option(
OptionData(
type=hikari.OptionType.MENTIONABLE,
Expand Down Expand Up @@ -652,7 +652,7 @@ def attachment(
Descriptor allowing access to the option value from within a command invocation.
"""
return t.cast(
hikari.Attachment,
"hikari.Attachment",
Option(
OptionData(
type=hikari.OptionType.ATTACHMENT,
Expand Down
8 changes: 4 additions & 4 deletions lightbulb/components/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
import asyncio
import typing as t
import uuid
from collections.abc import Generator
from collections.abc import Sequence

import async_timeout
import hikari
Expand All @@ -55,6 +53,8 @@
if t.TYPE_CHECKING:
from collections.abc import Awaitable
from collections.abc import Callable
from collections.abc import Generator
from collections.abc import Sequence

import typing_extensions as t_ex

Expand Down Expand Up @@ -343,7 +343,7 @@ def __init__(
menu: Menu,
interaction: hikari.ComponentInteraction,
component: base.BaseComponent[special_endpoints.MessageActionRowBuilder],
_timeout: async_timeout.Timeout,
_timeout: async_timeout.Timeout, # noqa: RUF052
) -> None:
super().__init__()

Expand Down Expand Up @@ -428,7 +428,7 @@ def selected_values_for(self, select: Select[T]) -> Sequence[T]:
if isinstance(select, TextSelect):
# This is **not** unreachable, pyright is just a silly sausage, and I don't want
# to add an overload for all the supported select types :D
return t.cast(Sequence[T], self.interaction.values)
return t.cast("Sequence[T]", self.interaction.values)

resolved_data = self.interaction.resolved
if resolved_data is None:
Expand Down
4 changes: 2 additions & 2 deletions lightbulb/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class RestAutocompleteContext(AutocompleteContext[T]):
def __init__(
self,
*args: t.Any,
_initial_response_callback: Callable[
_initial_response_callback: Callable[ # noqa: RUF052
[hikari.api.InteractionAutocompleteBuilder],
None,
],
Expand Down Expand Up @@ -518,7 +518,7 @@ class RestContext(Context):
def __init__(
self,
*args: t.Any,
_initial_response_callback: Callable[
_initial_response_callback: Callable[ # noqa: RUF052
[hikari.api.InteractionResponseBuilder],
None,
],
Expand Down
4 changes: 2 additions & 2 deletions lightbulb/di/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ def __init__(
self,
func: Callable[..., Awaitable[t.Any]],
self_: t.Any = None,
_cached_pos_or_kw_params: list[tuple[str, t.Any]] | None = None,
_cached_kw_only_params: dict[str, t.Any] | None = None,
_cached_pos_or_kw_params: list[tuple[str, t.Any]] | None = None, # noqa: RUF052
_cached_kw_only_params: dict[str, t.Any] | None = None, # noqa: RUF052
) -> None:
self._func = func
self._self: t.Any = self_
Expand Down
11 changes: 6 additions & 5 deletions lightbulb/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@
import abc
import logging
import typing as t
from collections.abc import Awaitable
from collections.abc import Callable
from collections.abc import Sequence

import hikari

from lightbulb import di
from lightbulb import tasks

if t.TYPE_CHECKING:
from collections.abc import Awaitable
from collections.abc import Callable
from collections.abc import Sequence

from lightbulb import client as client_
from lightbulb.internal import types

Expand Down Expand Up @@ -349,7 +350,7 @@ async def message_create_listener(event: hikari.MessageCreateEvent) -> None:
def _inner(
callback: Callable["t.Concatenate[EventT, ...]", Awaitable[None]],
) -> Callable[[EventT], Awaitable[None]]:
wrapped = t.cast(Callable[[EventT], Awaitable[None]], di.with_di(callback))
wrapped = t.cast("Callable[[EventT], Awaitable[None]]", di.with_di(callback))
self.add(_ListenerLoadable(wrapped, *event_types))
return wrapped

Expand Down Expand Up @@ -380,7 +381,7 @@ def error_handler(
if func is not None:
wrapped = di.with_di(func)
self.add(_ErrorHandlerLoadable(wrapped, priority)) # type: ignore[reportArgumentType]
return t.cast(ErrorHandlerT, wrapped)
return t.cast("ErrorHandlerT", wrapped)

def _inner(func_: ErrorHandlerT) -> ErrorHandlerT:
return self.error_handler(func_, priority=priority)
Expand Down
2 changes: 1 addition & 1 deletion lightbulb/prefab/concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import collections

import hikari # noqa: TCH002
import hikari # noqa: TC002

from lightbulb import context
from lightbulb import utils
Expand Down
2 changes: 1 addition & 1 deletion lightbulb/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ async def maybe_await(item: types.MaybeAwaitable[T]) -> T:
"""
if inspect.iscoroutine(item):
return await item
return t.cast(T, item)
return t.cast("T", item)

0 comments on commit 6bcac87

Please sign in to comment.