From 020e74ca166bdcf9b4420c14542fe4919700658d Mon Sep 17 00:00:00 2001 From: koen1711 Date: Wed, 29 May 2024 21:16:16 +0200 Subject: [PATCH] chore: fix pylint issues + black --- play/api/__init__.py | 5 +++-- play/api/events.py | 9 ++++----- play/api/generators.py | 5 +---- play/api/utils.py | 5 +++++ play/globals.py | 2 +- play/io/__init__.py | 4 ++-- play/objects/line.py | 10 +++++----- 7 files changed, 21 insertions(+), 19 deletions(-) diff --git a/play/api/__init__.py b/play/api/__init__.py index 8045a29..055e85b 100644 --- a/play/api/__init__.py +++ b/play/api/__init__.py @@ -4,9 +4,10 @@ import pygame -pygame.init() - from .generators import * from .events import * from .utils import * from .random import * + + +pygame.init() # pylint: disable=no-member diff --git a/play/api/events.py b/play/api/events.py index d8292e2..2202639 100644 --- a/play/api/events.py +++ b/play/api/events.py @@ -5,9 +5,7 @@ import pygame # pylint: disable=import-error -from ..globals import all_sprites -from ..utils.async_helpers import _make_async -from ..utils import color_name_to_rgb as _color_name_to_rgb +from ..globals import all_sprites, backdrop from ..io import screen, PYGAME_DISPLAY from ..io.keypress import ( pygame_key_to_name as _pygame_key_to_name, @@ -23,7 +21,8 @@ from ..objects.line import Line from ..objects.sprite import point_touching_sprite from ..physics import simulate_physics -from ..globals import BACKDROP +from ..utils import color_name_to_rgb as _color_name_to_rgb +from ..utils.async_helpers import _make_async _when_program_starts_callbacks = [] _clock = pygame.time.Clock() @@ -128,7 +127,7 @@ def _game_loop(): # 10. render sprites (with correct z-order) # 11. call event loop again - PYGAME_DISPLAY.fill(_color_name_to_rgb(BACKDROP)) + PYGAME_DISPLAY.fill(_color_name_to_rgb(backdrop)) # BACKGROUND COLOR # note: cannot use screen.fill((1, 1, 1)) because pygame's screen diff --git a/play/api/generators.py b/play/api/generators.py index 3885a05..8bf5fea 100644 --- a/play/api/generators.py +++ b/play/api/generators.py @@ -1,9 +1,6 @@ """Generators for creating new objects.""" -import asyncio as _asyncio -import random as _random - -from ..objects import Box, Circle, Line, Text, Group +from ..objects import Box, Circle, Line, Text def new_text( # pylint: disable=too-many-arguments diff --git a/play/api/utils.py b/play/api/utils.py index cba263e..ac04e9d 100644 --- a/play/api/utils.py +++ b/play/api/utils.py @@ -2,9 +2,14 @@ import asyncio as _asyncio import logging as _logging + import pygame # pylint: disable=import-error + from .events import _when_program_starts_callbacks, _game_loop, _loop from ..utils import color_name_to_rgb as _color_name_to_rgb +from ..globals import backdrop as _backdrop + +BACKDROP = _backdrop def start_program(): diff --git a/play/globals.py b/play/globals.py index 1c74da6..ddb1f2d 100644 --- a/play/globals.py +++ b/play/globals.py @@ -4,7 +4,7 @@ _walls = [] -BACKDROP = (255, 255, 255) +backdrop = (255, 255, 255) COLOR_NAMES = { "aliceblue": (240, 248, 255), diff --git a/play/io/__init__.py b/play/io/__init__.py index 78db43a..7489ea7 100644 --- a/play/io/__init__.py +++ b/play/io/__init__.py @@ -19,7 +19,7 @@ def __init__(self, width=800, height=600): self._width = width self._height = height PYGAME_DISPLAY = pygame.display.set_mode( - (width, height), pygame.DOUBLEBUF + (width, height), pygame.DOUBLEBUF # pylint: disable=no-member ) # pylint: disable=no-member pygame.display.set_caption("Python Play") self._fullscreen = False @@ -96,7 +96,7 @@ def enable_fullscreen(self): else: PYGAME_DISPLAY = pygame.display.set_mode( (self.width, self.height), - SCALED + NOFRAME + FULLSCREEN, + SCALED + NOFRAME + FULLSCREEN, # pylint: disable=undefined-variable 32, # pylint: disable=undefined-variable ) # all flags are necessary diff --git a/play/objects/line.py b/play/objects/line.py index 88a00ad..a14d0cb 100644 --- a/play/objects/line.py +++ b/play/objects/line.py @@ -69,7 +69,7 @@ def _compute_primary_surface(self): height = self.thickness + 1 self._primary_pygame_surface = pygame.Surface( - (width, height), pygame.SRCALPHA + (width, height), pygame.SRCALPHA # pylint: disable=no-member ) # pylint: disable=no-member # self._primary_pygame_surface.set_colorkey((255,255,255, 255)) # set background to transparent @@ -79,17 +79,17 @@ def _compute_primary_surface(self): self._compute_secondary_surface(force=True) def _compute_secondary_surface(self, force=False): - self._secondary_pygame_surface = ( + self._secondary_pygame_surface = ( # pylint: disable=attribute-defined-outside-init self._primary_pygame_surface.copy() - ) # pylint: disable=attribute-defined-outside-init + ) if force or self._transparency != 100: self._secondary_pygame_surface.set_alpha( round((self._transparency / 100.0) * 255) ) - self._should_recompute_secondary_surface = ( - False # pylint: disable=attribute-defined-outside-init + self._should_recompute_secondary_surface = ( # pylint: disable=attribute-defined-outside-init + False ) ##### color #####