From 613840ebcf303e84048d48ace37fb001c1afe687 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Sat, 6 May 2023 16:12:32 +0100 Subject: Apply fixes for ruff linting Co-authored-by: wookie184 Co-authored-by: Amrou Bellalouna --- bot/exts/fun/snakes/_utils.py | 44 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 24 deletions(-) (limited to 'bot/exts/fun/snakes/_utils.py') diff --git a/bot/exts/fun/snakes/_utils.py b/bot/exts/fun/snakes/_utils.py index 182fa9d9..5332cde2 100644 --- a/bot/exts/fun/snakes/_utils.py +++ b/bot/exts/fun/snakes/_utils.py @@ -6,7 +6,6 @@ import math import random from itertools import product from pathlib import Path -from typing import Union from PIL import Image from PIL.ImageDraw import ImageDraw @@ -132,7 +131,7 @@ def lerp(t: float, a: float, b: float) -> float: return a + t * (b - a) -class PerlinNoiseFactory(object): +class PerlinNoiseFactory: """ Callable that produces Perlin noise for an arbitrary point in an arbitrary number of dimensions. @@ -396,7 +395,7 @@ class SnakeAndLaddersGame: Listen for reactions until players have joined, and the game has been started. """ - def startup_event_check(reaction_: Reaction, user_: Union[User, Member]) -> bool: + def startup_event_check(reaction_: Reaction, user_: User | Member) -> bool: """Make sure that this reaction is what we want to operate on.""" return ( all(( @@ -445,14 +444,12 @@ class SnakeAndLaddersGame: # Allow game author or non-playing moderation staff to cancel a waiting game await self.cancel_game() return - else: - await self.player_leave(user) - elif reaction.emoji == START_EMOJI: - if self.ctx.author == user: - self.started = True - await self.start_game(user) - await startup.delete() - break + await self.player_leave(user) + elif reaction.emoji == START_EMOJI and self.ctx.author == user: + self.started = True + await self.start_game(user) + await startup.delete() + break await startup.remove_reaction(reaction.emoji, user) @@ -461,7 +458,7 @@ class SnakeAndLaddersGame: await self.cancel_game() return # We're done, no reactions for the last 5 minutes - async def _add_player(self, user: Union[User, Member]) -> None: + async def _add_player(self, user: User | Member) -> None: """Add player to game.""" self.players.append(user) self.player_tiles[user.id] = 1 @@ -470,7 +467,7 @@ class SnakeAndLaddersGame: im = Image.open(io.BytesIO(avatar_bytes)).resize((BOARD_PLAYER_SIZE, BOARD_PLAYER_SIZE)) self.avatar_images[user.id] = im - async def player_join(self, user: Union[User, Member]) -> None: + async def player_join(self, user: User | Member) -> None: """ Handle players joining the game. @@ -496,7 +493,7 @@ class SnakeAndLaddersGame: delete_after=10 ) - async def player_leave(self, user: Union[User, Member]) -> bool: + async def player_leave(self, user: User | Member) -> bool: """ Handle players leaving the game. @@ -531,17 +528,17 @@ class SnakeAndLaddersGame: await self.channel.send("**Snakes and Ladders**: Game has been canceled.") self._destruct() - async def start_game(self, user: Union[User, Member]) -> None: + async def start_game(self, user: User | Member) -> None: """ Allow the game author to begin the game. The game cannot be started if the game is in a waiting state. """ - if not user == self.author: + if user != self.author: await self.channel.send(user.mention + " Only the author of the game can start it.", delete_after=10) return - if not self.state == "waiting": + if self.state != "waiting": await self.channel.send(user.mention + " The game cannot be started at this time.", delete_after=10) return @@ -552,7 +549,7 @@ class SnakeAndLaddersGame: async def start_round(self) -> None: """Begin the round.""" - def game_event_check(reaction_: Reaction, user_: Union[User, Member]) -> bool: + def game_event_check(reaction_: Reaction, user_: User | Member) -> bool: """Make sure that this reaction is what we want to operate on.""" return ( all(( @@ -626,8 +623,7 @@ class SnakeAndLaddersGame: # Only allow non-playing moderation staff to cancel a running game await self.cancel_game() return - else: - is_surrendered = await self.player_leave(user) + is_surrendered = await self.player_leave(user) await self.positions.remove_reaction(reaction.emoji, user) @@ -645,7 +641,7 @@ class SnakeAndLaddersGame: if not is_surrendered: await self._complete_round() - async def player_roll(self, user: Union[User, Member]) -> None: + async def player_roll(self, user: User | Member) -> None: """Handle the player's roll.""" if user.id not in self.player_tiles: await self.channel.send(user.mention + " You are not in the match.", delete_after=10) @@ -692,7 +688,7 @@ class SnakeAndLaddersGame: await self.channel.send("**Snakes and Ladders**: " + winner.mention + " has won the game! :tada:") self._destruct() - def _check_winner(self) -> Union[User, Member]: + def _check_winner(self) -> User | Member: """Return a winning member if we're in the post-round state and there's a winner.""" if self.state != "post_round": return None @@ -717,6 +713,6 @@ class SnakeAndLaddersGame: return x_level, y_level @staticmethod - def _is_moderator(user: Union[User, Member]) -> bool: + def _is_moderator(user: User | Member) -> bool: """Return True if the user is a Moderator.""" - return any(role.id in MODERATION_ROLES for role in getattr(user, 'roles', [])) + return any(role.id in MODERATION_ROLES for role in getattr(user, "roles", [])) -- cgit v1.2.3 From 6115936161ce67fd87747600c0b43068624da42a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 May 2023 19:55:12 +0000 Subject: Bump ruff from 0.0.265 to 0.0.267 (#1276) * Bump ruff from 0.0.265 to 0.0.267 Bumps [ruff](https://github.com/charliermarsh/ruff) from 0.0.265 to 0.0.267. - [Release notes](https://github.com/charliermarsh/ruff/releases) - [Changelog](https://github.com/charliermarsh/ruff/blob/main/BREAKING_CHANGES.md) - [Commits](https://github.com/charliermarsh/ruff/compare/v0.0.265...v0.0.267) --- updated-dependencies: - dependency-name: ruff dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * Fix linting errors from new ruff rules --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Chris Lovering --- bot/exts/core/error_handler.py | 4 ++-- bot/exts/events/trivianight/trivianight.py | 2 +- bot/exts/fun/duck_game.py | 2 +- bot/exts/fun/snakes/_utils.py | 2 +- bot/utils/pagination.py | 2 +- poetry.lock | 38 +++++++++++++++--------------- pyproject.toml | 2 +- 7 files changed, 26 insertions(+), 26 deletions(-) (limited to 'bot/exts/fun/snakes/_utils.py') diff --git a/bot/exts/core/error_handler.py b/bot/exts/core/error_handler.py index 62dee53c..81b923fd 100644 --- a/bot/exts/core/error_handler.py +++ b/bot/exts/core/error_handler.py @@ -59,7 +59,7 @@ class CommandErrorHandler(commands.Cog): error = getattr(error, "original", error) logging.debug( - f"Error Encountered: {type(error).__name__} - {str(error)}, " + f"Error Encountered: {type(error).__name__} - {error!s}, " f"Command: {ctx.command}, " f"Author: {ctx.author}, " f"Channel: {ctx.channel}" @@ -156,7 +156,7 @@ class CommandErrorHandler(commands.Cog): if ctx.guild is not None: scope.set_extra("jump_to", ctx.message.jump_url) - log.exception(f"Unhandled command error: {str(error)}", exc_info=error) + log.exception(f"Unhandled command error: {error!s}", exc_info=error) async def send_command_suggestion(self, ctx: commands.Context, command_name: str) -> None: """Sends user similar commands if any can be found.""" diff --git a/bot/exts/events/trivianight/trivianight.py b/bot/exts/events/trivianight/trivianight.py index f90d32e0..e0db45d8 100644 --- a/bot/exts/events/trivianight/trivianight.py +++ b/bot/exts/events/trivianight/trivianight.py @@ -90,7 +90,7 @@ class TriviaNightCog(commands.Cog): try: serialized_json = loads(json_text) except JSONDecodeError as error: - raise commands.BadArgument(f"Looks like something went wrong:\n{str(error)}") + raise commands.BadArgument(f"Looks like something went wrong:\n{error!s}") self.game = TriviaNightGame(serialized_json) self.question_closed = asyncio.Event() diff --git a/bot/exts/fun/duck_game.py b/bot/exts/fun/duck_game.py index 3f34ece7..fbdc9ea2 100644 --- a/bot/exts/fun/duck_game.py +++ b/bot/exts/fun/duck_game.py @@ -248,7 +248,7 @@ class DuckGamesDirector(commands.Cog): if answer in game.solutions: game.claimed_answers[answer] = msg.author game.scores[msg.author] += CORRECT_SOLN - await self.append_to_found_embed(game, f"{str(answer):12s} - {msg.author.display_name}") + await self.append_to_found_embed(game, f"{answer!s:12s} - {msg.author.display_name}") else: await msg.add_reaction(EMOJI_WRONG) game.scores[msg.author] += INCORRECT_SOLN diff --git a/bot/exts/fun/snakes/_utils.py b/bot/exts/fun/snakes/_utils.py index 5332cde2..ffffcd34 100644 --- a/bot/exts/fun/snakes/_utils.py +++ b/bot/exts/fun/snakes/_utils.py @@ -489,7 +489,7 @@ class SnakeAndLaddersGame: await self.channel.send( f"**Snakes and Ladders**: {user.mention} has joined the game.\n" - f"There are now {str(len(self.players))} players in the game.", + f"There are now {len(self.players)!s} players in the game.", delete_after=10 ) diff --git a/bot/utils/pagination.py b/bot/utils/pagination.py index df0eb942..ef3186d0 100644 --- a/bot/utils/pagination.py +++ b/bot/utils/pagination.py @@ -190,7 +190,7 @@ class LinePaginator(Paginator): for emoji in PAGINATION_EMOJI: # Add all the applicable emoji to the message - log.trace(f"Adding reaction: {repr(emoji)}") + log.trace(f"Adding reaction: {emoji!r}") await message.add_reaction(emoji) while True: diff --git a/poetry.lock b/poetry.lock index ff29717c..e503d1cc 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1535,29 +1535,29 @@ ocsp = ["cryptography (>=36.0.1)", "pyopenssl (==20.0.1)", "requests (>=2.26.0)" [[package]] name = "ruff" -version = "0.0.265" +version = "0.0.267" description = "An extremely fast Python linter, written in Rust." category = "dev" optional = false python-versions = ">=3.7" files = [ - {file = "ruff-0.0.265-py3-none-macosx_10_7_x86_64.whl", hash = "sha256:30ddfe22de6ce4eb1260408f4480bbbce998f954dbf470228a21a9b2c45955e4"}, - {file = "ruff-0.0.265-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:a11bd0889e88d3342e7bc514554bb4461bf6cc30ec115821c2425cfaac0b1b6a"}, - {file = "ruff-0.0.265-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2a9b38bdb40a998cbc677db55b6225a6c4fadcf8819eb30695e1b8470942426b"}, - {file = "ruff-0.0.265-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:a8b44a245b60512403a6a03a5b5212da274d33862225c5eed3bcf12037eb19bb"}, - {file = "ruff-0.0.265-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:b279fa55ea175ef953208a6d8bfbcdcffac1c39b38cdb8c2bfafe9222add70bb"}, - {file = "ruff-0.0.265-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:5028950f7af9b119d43d91b215d5044976e43b96a0d1458d193ef0dd3c587bf8"}, - {file = "ruff-0.0.265-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:4057eb539a1d88eb84e9f6a36e0a999e0f261ed850ae5d5817e68968e7b89ed9"}, - {file = "ruff-0.0.265-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:d586e69ab5cbf521a1910b733412a5735936f6a610d805b89d35b6647e2a66aa"}, - {file = "ruff-0.0.265-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:aa17b13cd3f29fc57d06bf34c31f21d043735cc9a681203d634549b0e41047d1"}, - {file = "ruff-0.0.265-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:9ac13b11d9ad3001de9d637974ec5402a67cefdf9fffc3929ab44c2fcbb850a1"}, - {file = "ruff-0.0.265-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:62a9578b48cfd292c64ea3d28681dc16b1aa7445b7a7709a2884510fc0822118"}, - {file = "ruff-0.0.265-py3-none-musllinux_1_2_i686.whl", hash = "sha256:d0f9967f84da42d28e3d9d9354cc1575f96ed69e6e40a7d4b780a7a0418d9409"}, - {file = "ruff-0.0.265-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:1d5a8de2fbaf91ea5699451a06f4074e7a312accfa774ad9327cde3e4fda2081"}, - {file = "ruff-0.0.265-py3-none-win32.whl", hash = "sha256:9e9db5ccb810742d621f93272e3cc23b5f277d8d00c4a79668835d26ccbe48dd"}, - {file = "ruff-0.0.265-py3-none-win_amd64.whl", hash = "sha256:f54facf286103006171a00ce20388d88ed1d6732db3b49c11feb9bf3d46f90e9"}, - {file = "ruff-0.0.265-py3-none-win_arm64.whl", hash = "sha256:c78470656e33d32ddc54e8482b1b0fc6de58f1195586731e5ff1405d74421499"}, - {file = "ruff-0.0.265.tar.gz", hash = "sha256:53c17f0dab19ddc22b254b087d1381b601b155acfa8feed514f0d6a413d0ab3a"}, + {file = "ruff-0.0.267-py3-none-macosx_10_7_x86_64.whl", hash = "sha256:4adbbbe314d8fcc539a245065bad89446a3cef2e0c9cf70bf7bb9ed6fe31856d"}, + {file = "ruff-0.0.267-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:67254ae34c38cba109fdc52e4a70887de1f850fb3971e5eeef343db67305d1c1"}, + {file = "ruff-0.0.267-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:bbe104f21a429b77eb5ac276bd5352fd8c0e1fbb580b4c772f77ee8c76825654"}, + {file = "ruff-0.0.267-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:db33deef2a5e1cf528ca51cc59dd764122a48a19a6c776283b223d147041153f"}, + {file = "ruff-0.0.267-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9adf1307fa9d840d1acaa477eb04f9702032a483214c409fca9dc46f5f157fe3"}, + {file = "ruff-0.0.267-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:0afca3633c8e2b6c0a48ad0061180b641b3b404d68d7e6736aab301c8024c424"}, + {file = "ruff-0.0.267-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:2972241065b1c911bce3db808837ed10f4f6f8a8e15520a4242d291083605ab6"}, + {file = "ruff-0.0.267-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:f731d81cb939e757b0335b0090f18ca2e9ff8bcc8e6a1cf909245958949b6e11"}, + {file = "ruff-0.0.267-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:20c594eb56c19063ef5a57f89340e64c6550e169d6a29408a45130a8c3068adc"}, + {file = "ruff-0.0.267-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:45d61a2b01bdf61581a2ee039503a08aa603dc74a6bbe6fb5d1ce3052f5370e5"}, + {file = "ruff-0.0.267-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:2107cec3699ca4d7bd41543dc1d475c97ae3a21ea9212238b5c2088fa8ee7722"}, + {file = "ruff-0.0.267-py3-none-musllinux_1_2_i686.whl", hash = "sha256:786de30723c71fc46b80a173c3313fc0dbe73c96bd9da8dd1212cbc2f84cdfb2"}, + {file = "ruff-0.0.267-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:5a898953949e37c109dd242cfcf9841e065319995ebb7cdfd213b446094a942f"}, + {file = "ruff-0.0.267-py3-none-win32.whl", hash = "sha256:d12ab329474c46b96d962e2bdb92e3ad2144981fe41b89c7770f370646c0101f"}, + {file = "ruff-0.0.267-py3-none-win_amd64.whl", hash = "sha256:d09aecc9f5845586ba90911d815f9772c5a6dcf2e34be58c6017ecb124534ac4"}, + {file = "ruff-0.0.267-py3-none-win_arm64.whl", hash = "sha256:7df7eb5f8d791566ba97cc0b144981b9c080a5b861abaf4bb35a26c8a77b83e9"}, + {file = "ruff-0.0.267.tar.gz", hash = "sha256:632cec7bbaf3c06fcf0a72a1dd029b7d8b7f424ba95a574aaa135f5d20a00af7"}, ] [[package]] @@ -1850,4 +1850,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "3.11.*" -content-hash = "71a0cff64d83d0a769857e9433e77a0521fc8477d78d07784ca4672f3b1a4bab" +content-hash = "41fe799b19f2913cc2bebab95ce15033d16c73010139c352f216a20bb36c876f" diff --git a/pyproject.toml b/pyproject.toml index 6be8b28a..5c93303e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,7 +32,7 @@ isort = "5.12.0" pip-licenses = "4.3.1" pre-commit = "3.3.1" python-dotenv = "1.0.0" -ruff = "0.0.265" +ruff = "0.0.267" taskipy = "1.10.4" [tool.taskipy.tasks] -- cgit v1.2.3