From 1e0af277fe1b00657178cf1f426a03d23cab3292 Mon Sep 17 00:00:00 2001 From: Michel Wilhelm Date: Wed, 5 Feb 2025 12:06:07 -0300 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20(game.py,=20signals.py):?= =?UTF-8?q?=20Refactor=20comparison=20operators=20for=20better=20readabili?= =?UTF-8?q?ty=20=F0=9F=94=A7=20(apps.py):=20Import=20signals=20in=20ready?= =?UTF-8?q?=20method=20to=20ensure=20signals=20are=20loaded=20when=20the?= =?UTF-8?q?=20app=20starts=20=F0=9F=94=A7=20(pyproject.toml):=20Add=20PGH0?= =?UTF-8?q?04=20to=20lint=20ignore=20list=20to=20avoid=20linting=20errors?= =?UTF-8?q?=20related=20to=20PostgreSQL-specific=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/resources/game.py | 1 - game/apps.py | 2 +- game/signals.py | 4 ++-- pyproject.toml | 1 + 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/resources/game.py b/api/resources/game.py index cdb1c70..4d603ce 100644 --- a/api/resources/game.py +++ b/api/resources/game.py @@ -46,7 +46,6 @@ class GameEventResource(APIView): def post(self, request, game_id): """Creates a new event""" - try: game = Game.objects.get(pk=game_id) except Game.DoesNotExist: diff --git a/game/apps.py b/game/apps.py index a3ec9a7..ca3ef88 100644 --- a/game/apps.py +++ b/game/apps.py @@ -7,4 +7,4 @@ class GameConfig(AppConfig): verbose_name_plural = 'Games' def ready(self): - pass + from game import signals # noqa diff --git a/game/signals.py b/game/signals.py index 43b3099..384943c 100644 --- a/game/signals.py +++ b/game/signals.py @@ -8,7 +8,7 @@ from .models import EventTypes, Game, GameEvent, GameStatuses @receiver(post_save, sender=Game) def game_start(sender, signal, instance, **kwargs): """If the game was just created, insert the first event START_GAME""" - if not instance.status == GameStatuses.NOT_PLAYED: + if instance.status != GameStatuses.NOT_PLAYED: return GameEvent.objects.get_or_create(game=instance, type=EventTypes.START_GAME) @@ -16,7 +16,7 @@ def game_start(sender, signal, instance, **kwargs): @receiver(pre_save, sender=GameEvent) def identify_click_event(sender, signal, instance, **kwargs): """Verify what is on the naive click: mine, point or empty""" - if not instance.type == EventTypes.CLICK_NAIVE: + if instance.type != EventTypes.CLICK_NAIVE: return if instance.row is None and instance.col is None: diff --git a/pyproject.toml b/pyproject.toml index fea9d8f..9de1dc3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -74,6 +74,7 @@ lint.ignore = [ "RUF012", "N806", "ARG002", + "PGH004", "N805", # Missing type annotation for self in method (Pydantic don't like this) "SIM108", # Use ternary operator {contents} instead of if-else-block "RUF009", # Missing dataclass field.