From 9d129c0c55bf70a38e9027238a59f303af968eeb Mon Sep 17 00:00:00 2001 From: onerandomusername Date: Mon, 20 Feb 2023 16:25:45 -0500 Subject: [PATCH] update per review --- disnake/enums.py | 8 ++++---- disnake/ext/commands/base_core.py | 4 ++-- disnake/ext/commands/core.py | 4 ++-- disnake/ext/commands/ctx_menus_core.py | 4 ++-- disnake/ext/commands/params.py | 4 ++-- disnake/ext/commands/view.py | 8 ++++---- disnake/interactions/application_command.py | 4 ++-- disnake/state.py | 2 +- disnake/ui/select/channel.py | 2 +- disnake/ui/select/string.py | 2 +- disnake/utils.py | 2 +- examples/basic_voice.py | 6 ++---- examples/converters.py | 6 ++---- examples/guessing_game.py | 3 +-- pyproject.toml | 8 +++----- 15 files changed, 30 insertions(+), 37 deletions(-) diff --git a/disnake/enums.py b/disnake/enums.py index 4e21f3f0bc..2ce7b0a20b 100644 --- a/disnake/enums.py +++ b/disnake/enums.py @@ -734,7 +734,7 @@ def __str__(self) -> str: # reference: https://discord.com/developers/docs/reference#locales class Locale(Enum): bg = "bg" - "Bulgarian | български" + "Bulgarian | български" # noqa: RUF001 cs = "cs" "Czech | Čeština" da = "da" @@ -742,7 +742,7 @@ class Locale(Enum): de = "de" "German | Deutsch" el = "el" - "Greek | Ελληνικά" + "Greek | Ελληνικά" # noqa: RUF001 en_GB = "en-GB" "English, UK | English, UK" en_US = "en-US" @@ -780,7 +780,7 @@ class Locale(Enum): ro = "ro" "Romanian, Romania | Română" ru = "ru" - "Russian | Pусский" + "Russian | Pусский" # noqa: RUF001 sv_SE = "sv-SE" "Swedish | Svenska" th = "th" @@ -788,7 +788,7 @@ class Locale(Enum): tr = "tr" "Turkish | Türkçe" uk = "uk" - "Ukrainian | Українська" + "Ukrainian | Українська" # noqa: RUF001 vi = "vi" "Vietnamese | Tiếng Việt" zh_CN = "zh-CN" diff --git a/disnake/ext/commands/base_core.py b/disnake/ext/commands/base_core.py index dd5db0c932..043c1242a2 100644 --- a/disnake/ext/commands/base_core.py +++ b/disnake/ext/commands/base_core.py @@ -627,8 +627,8 @@ async def can_run(self, inter: ApplicationCommandInteraction) -> bool: if not predicates: # since we have no checks, then we just return True. return True - else: - return await async_all(predicate(inter) for predicate in predicates) # type: ignore + + return await async_all(predicate(inter) for predicate in predicates) # type: ignore finally: inter.application_command = original diff --git a/disnake/ext/commands/core.py b/disnake/ext/commands/core.py index 188edb3d6e..6bdd417c6a 100644 --- a/disnake/ext/commands/core.py +++ b/disnake/ext/commands/core.py @@ -1149,8 +1149,8 @@ async def can_run(self, ctx: Context) -> bool: if not predicates: # since we have no checks, then we just return True. return True - else: - return await disnake.utils.async_all(predicate(ctx) for predicate in predicates) # type: ignore + + return await disnake.utils.async_all(predicate(ctx) for predicate in predicates) # type: ignore finally: ctx.command = original diff --git a/disnake/ext/commands/ctx_menus_core.py b/disnake/ext/commands/ctx_menus_core.py index 835bd674e6..7cf836fbef 100644 --- a/disnake/ext/commands/ctx_menus_core.py +++ b/disnake/ext/commands/ctx_menus_core.py @@ -125,7 +125,7 @@ async def __call__( self, interaction: ApplicationCommandInteraction, target: Any = None, *args, **kwargs ) -> None: # the target may just not be passed in - args = (target or interaction.target,) + args + args = (target or interaction.target, *args) if self.cog is not None: await safe_call(self.callback, self.cog, interaction, *args, **kwargs) else: @@ -221,7 +221,7 @@ async def __call__( self, interaction: ApplicationCommandInteraction, target: Any = None, *args, **kwargs ) -> None: # the target may just not be passed in - args = (target or interaction.target,) + args + args = (target or interaction.target, *args) if self.cog is not None: await safe_call(self.callback, self.cog, interaction, *args, **kwargs) else: diff --git a/disnake/ext/commands/params.py b/disnake/ext/commands/params.py index fbbd712f60..4190821796 100644 --- a/disnake/ext/commands/params.py +++ b/disnake/ext/commands/params.py @@ -629,8 +629,8 @@ async def convert_argument(self, inter: ApplicationCommandInteraction, argument: argument = self.converter(inter, argument) if inspect.isawaitable(argument): return await argument - else: - return argument + + return argument except errors.CommandError: raise except Exception as e: diff --git a/disnake/ext/commands/view.py b/disnake/ext/commands/view.py index d76233146a..f4c2497c34 100644 --- a/disnake/ext/commands/view.py +++ b/disnake/ext/commands/view.py @@ -5,8 +5,8 @@ # map from opening quotes to closing quotes _quotes = { '"': '"', - "‘": "’", - "‚": "‛", + "‘": "’", # noqa: RUF001 + "‚": "‛", # noqa: RUF001 "“": "”", "„": "‟", "⹂": "⹂", @@ -15,10 +15,10 @@ "〝": "〞", "﹁": "﹂", "﹃": "﹄", - """: """, + """: """, # noqa: RUF001 "「": "」", "«": "»", - "‹": "›", + "‹": "›", # noqa: RUF001 "《": "》", "〈": "〉", } diff --git a/disnake/interactions/application_command.py b/disnake/interactions/application_command.py index 7831fbaf49..95daabce79 100644 --- a/disnake/interactions/application_command.py +++ b/disnake/interactions/application_command.py @@ -231,7 +231,7 @@ def _get_chain_and_kwargs( for option in self.options: if option.value is None: # Extend the chain and collect kwargs in the nesting - return option._get_chain_and_kwargs(chain + (option.name,)) + return option._get_chain_and_kwargs((*chain, option.name)) return chain, {o.name: o.value for o in self.options} return chain, {} @@ -316,7 +316,7 @@ def _get_chain_and_kwargs( for option in self.options: if option.value is None: # Extend the chain and collect kwargs in the nesting - return option._get_chain_and_kwargs(chain + (option.name,)) + return option._get_chain_and_kwargs((*chain, option.name)) return chain, {o.name: o.value for o in self.options} return chain, {} diff --git a/disnake/state.py b/disnake/state.py index acb872e02b..d979608a7d 100644 --- a/disnake/state.py +++ b/disnake/state.py @@ -652,7 +652,7 @@ async def query_members( presences=presences, nonce=request.nonce, ) - return await asyncio.wait_for(request.wait(), timeout=30.0) # noqa: TRY300 + return await asyncio.wait_for(request.wait(), timeout=30.0) except asyncio.TimeoutError: _log.warning( "Timed out waiting for chunks with query %r and limit %d for guild_id %d", diff --git a/disnake/ui/select/channel.py b/disnake/ui/select/channel.py index a455172799..b5e5f15dbd 100644 --- a/disnake/ui/select/channel.py +++ b/disnake/ui/select/channel.py @@ -62,7 +62,7 @@ class ChannelSelect(BaseSelect[ChannelSelectMenu, "InteractionChannel", V_co]): A list of channels that have been selected by the user. """ - __repr_attributes__: Tuple[str, ...] = BaseSelect.__repr_attributes__ + ("channel_types",) + __repr_attributes__: Tuple[str, ...] = (*BaseSelect.__repr_attributes__, "channel_types") @overload def __init__( diff --git a/disnake/ui/select/string.py b/disnake/ui/select/string.py index 0a975c2aa8..4c44bf994d 100644 --- a/disnake/ui/select/string.py +++ b/disnake/ui/select/string.py @@ -96,7 +96,7 @@ class StringSelect(BaseSelect[StringSelectMenu, str, V_co]): A list of values that have been selected by the user. """ - __repr_attributes__: Tuple[str, ...] = BaseSelect.__repr_attributes__ + ("options",) + __repr_attributes__: Tuple[str, ...] = (*BaseSelect.__repr_attributes__, "options") @overload def __init__( diff --git a/disnake/utils.py b/disnake/utils.py index 209e0994b1..b38e79f0d6 100644 --- a/disnake/utils.py +++ b/disnake/utils.py @@ -1152,7 +1152,7 @@ def flatten_literal_params(parameters: Iterable[Any]) -> Tuple[Any, ...]: def normalise_optional_params(parameters: Iterable[Any]) -> Tuple[Any, ...]: none_cls = type(None) - return tuple(p for p in parameters if p is not none_cls) + (none_cls,) + return (*tuple(p for p in parameters if p is not none_cls), none_cls) def evaluate_annotation( diff --git a/examples/basic_voice.py b/examples/basic_voice.py index d68e966a1e..c876e1c0b3 100644 --- a/examples/basic_voice.py +++ b/examples/basic_voice.py @@ -73,8 +73,7 @@ async def join(self, ctx, *, channel: disnake.VoiceChannel): """Joins a voice channel""" if ctx.voice_client is not None: - await ctx.voice_client.move_to(channel) - return + return await ctx.voice_client.move_to(channel) await channel.connect() @@ -112,8 +111,7 @@ async def volume(self, ctx, volume: int): """Changes the player's volume""" if ctx.voice_client is None: - await ctx.send("Not connected to a voice channel.") - return + return await ctx.send("Not connected to a voice channel.") ctx.voice_client.source.volume = volume / 100 await ctx.send(f"Changed volume to {volume}%") diff --git a/examples/converters.py b/examples/converters.py index 638dbcb547..8ce61b6a69 100644 --- a/examples/converters.py +++ b/examples/converters.py @@ -41,8 +41,7 @@ async def userinfo_error(ctx: commands.Context, error: commands.CommandError): # If the conversion above fails for any reason, it will raise `commands.UserNotFound` # so we handle this in this error handler: if isinstance(error, commands.UserNotFound): - await ctx.send("Couldn't find that user.") - return + return await ctx.send("Couldn't find that user.") @bot.command() @@ -71,8 +70,7 @@ async def multiply(ctx: commands.Context, number: int, maybe: bool): # See: https://docs.disnake.dev/en/stable/ext/commands/commands.html#bool if maybe is True: - await ctx.send(str(number * 2)) - return + return await ctx.send(str(number * 2)) await ctx.send(str(number * 5)) diff --git a/examples/guessing_game.py b/examples/guessing_game.py index af2763ec6e..f3ebb7343e 100644 --- a/examples/guessing_game.py +++ b/examples/guessing_game.py @@ -29,8 +29,7 @@ def is_guess_message(m: disnake.Message): try: guess = await ctx.bot.wait_for("message", check=is_guess_message, timeout=10) except asyncio.TimeoutError: - await ctx.send(f"Sorry, you took too long. The answer was {answer}.") - return + return await ctx.send(f"Sorry, you took too long. The answer was {answer}.") if int(guess.content) == answer: await ctx.send("You guessed correctly!") diff --git a/pyproject.toml b/pyproject.toml index e4bfa5edc0..552e721f82 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -69,13 +69,12 @@ select = [ # "SIM", # flake8-simplify "TID251", # flake8-tidy-imports, replaces S404 # "TCH", # flake8-type-checking - # "RUF", # ruff specific exceptions - "RUF100", # unused noqa directive + "RUF", # ruff specific exceptions "PT", # flake8-pytest-style "Q", # flake8-quotes "T20", # flake8-print "PGH", # pygrep-hooks - "TRY002", "TRY004","TRY300", # tryceratops + "TRY002", "TRY004", # tryceratops ] ignore = [ # star imports @@ -95,13 +94,13 @@ ignore = [ "B026", # backwards star-arg unpacking "E501", # line too long "E731", # assigning lambdas to variables + "RUF004", # keyword args must be supplied after starred arguments "T201", # print statements ] [tool.ruff.per-file-ignores] "disnake/__main__.py" = ["T201"] "disnake/i18n.py" = ["B027"] # lib bug -"disnake/types/**.py" = ["TCH"] "disnake/**.py" = ["PT"] "examples/*.py" = ["B008", "T201", "PT"] "examples/basic_voice.py" = ["S104"] @@ -113,7 +112,6 @@ ignore = [ fixture-parentheses = false mark-parentheses = false -[tool.ruff.flake8-tidy-imports] [tool.ruff.flake8-tidy-imports.banned-api] "subprocess".msg = "Consider possible security implications associated with the subprocess module." # replaces S404