Skip to content

Commit 07b53ea

Browse files
committed
Improve typing
1 parent f61c9b1 commit 07b53ea

File tree

12 files changed

+42
-60
lines changed

12 files changed

+42
-60
lines changed

pygame_menu/_decorator.py

+20-21
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,26 @@
2828
CallableNoArgsType
2929

3030
# Decoration constants
31-
DECORATION_ARC = 2000
32-
DECORATION_BASEIMAGE = 2001
33-
DECORATION_BEZIER = 2002
34-
DECORATION_CALLABLE = 2003
35-
DECORATION_CALLABLE_NO_ARGS = 2015
36-
DECORATION_CIRCLE = 2004
37-
DECORATION_ELLIPSE = 2005
38-
DECORATION_FILL = 2020
39-
DECORATION_LINE = 2006
40-
DECORATION_NONE = 2007
41-
DECORATION_PIE = 2008
42-
DECORATION_PIXEL = 209
43-
DECORATION_POLYGON = 2010
44-
DECORATION_RECT = 2011
45-
DECORATION_SURFACE = 2012
46-
DECORATION_TEXT = 2013
47-
DECORATION_TEXTURE_POLYGON = 2014
48-
49-
DECOR_TYPE_PREV = 'prev'
50-
DECOR_TYPE_POST = 'post'
31+
DECORATION_ARC: int = 2000
32+
DECORATION_BASEIMAGE: int = 2001
33+
DECORATION_BEZIER: int = 2002
34+
DECORATION_CALLABLE: int = 2003
35+
DECORATION_CALLABLE_NO_ARGS: int = 2015
36+
DECORATION_CIRCLE: int = 2004
37+
DECORATION_ELLIPSE: int = 2005
38+
DECORATION_FILL: int = 2020
39+
DECORATION_LINE: int = 2006
40+
DECORATION_NONE: int = 2007
41+
DECORATION_PIE: int = 2008
42+
DECORATION_PIXEL: int = 209
43+
DECORATION_POLYGON: int = 2010
44+
DECORATION_RECT: int = 2011
45+
DECORATION_SURFACE: int = 2012
46+
DECORATION_TEXT: int = 2013
47+
DECORATION_TEXTURE_POLYGON: int = 2014
48+
49+
DECOR_TYPE_PREV: str = 'prev'
50+
DECOR_TYPE_POST: str = 'post'
5151

5252

5353
# noinspection PyProtectedMember
@@ -956,7 +956,6 @@ def draw_post(self, surface: 'pygame.Surface') -> 'Decorator':
956956
self._draw_assemble_cache(DECOR_TYPE_POST, self._decor[DECOR_TYPE_POST], surface)
957957
return self
958958

959-
# noinspection PyArgumentList
960959
def _draw(self, deco: List[Tuple[int, str, Any]], surface: 'pygame.Surface') -> None:
961960
"""
962961
Draw.

pygame_menu/_scrollarea.py

-2
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,6 @@ def draw(self, surface: 'pygame.Surface') -> 'ScrollArea':
496496
surface.blit(self._bg_surface, (self._rect.x - self._extend_x, self._rect.y - self._extend_y))
497497

498498
# Draw world surface
499-
# noinspection PyTypeChecker
500499
surface.blit(self._world, self._view_rect.topleft, (self.get_offsets(), self._view_rect.size))
501500

502501
# Then draw scrollbars
@@ -923,7 +922,6 @@ def scroll_to(self, orientation: str, value: NumberType) -> 'ScrollArea':
923922
break
924923
return self
925924

926-
# noinspection PyTypeChecker
927925
def scroll_to_rect(
928926
self,
929927
rect: 'pygame.Rect',

pygame_menu/baseimage.py

-2
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,6 @@ def apply_image_function(
554554
g = int(max(0, min(g, 255)))
555555
b = int(max(0, min(b, 255)))
556556
a = int(max(0, min(a, 255)))
557-
# noinspection PyArgumentList
558557
self.set_at((x, y), pygame.Color(r, g, b, a))
559558
return self
560559

@@ -605,7 +604,6 @@ def pick_channels(self, channels: ChannelType) -> 'BaseImage':
605604
g = 0
606605
if 'b' not in channels:
607606
b = 0
608-
# noinspection PyArgumentList
609607
self._surface.set_at((x, y), pygame.Color(r, g, b, a))
610608
return self
611609

pygame_menu/controls.py

+13-14
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,25 @@
3636
]
3737

3838
# Imports
39-
# noinspection PyUnresolvedReferences
40-
import pygame_menu
4139
import pygame.locals as _locals
4240
from pygame.event import Event as EventType
41+
from pygame_menu._types import Tuple2IntType
4342
from typing import Union
4443

45-
WidgetType = Union['pygame_menu.Menu', 'pygame_menu.widgets.Widget']
44+
WidgetType = Union['pygame_menu.Menu', 'pygame_menu.widgets.Widget'] # type: ignore
4645

4746
# Joy pad
48-
JOY_AXIS_X = 0
49-
JOY_AXIS_Y = 1
50-
JOY_BUTTON_BACK = 1
51-
JOY_BUTTON_SELECT = 0
52-
JOY_DEADZONE = 0.5
53-
JOY_DELAY = 300 # ms
54-
JOY_DOWN = (0, -1)
55-
JOY_LEFT = (-1, 0)
56-
JOY_REPEAT = 100 # ms
57-
JOY_RIGHT = (1, 0)
58-
JOY_UP = (0, 1)
47+
JOY_AXIS_X: int = 0
48+
JOY_AXIS_Y: int = 1
49+
JOY_BUTTON_BACK: int = 1
50+
JOY_BUTTON_SELECT: int = 0
51+
JOY_DEADZONE: float = 0.5
52+
JOY_DELAY: int = 300 # ms
53+
JOY_DOWN: Tuple2IntType = (0, -1)
54+
JOY_LEFT: Tuple2IntType = (-1, 0)
55+
JOY_REPEAT: int = 100 # ms
56+
JOY_RIGHT: Tuple2IntType = (1, 0)
57+
JOY_UP: Tuple2IntType = (0, 1)
5958

6059
# Keyboard events
6160
KEY_APPLY = _locals.K_RETURN

pygame_menu/examples/other/calculator.py

-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ def process_events(self, events: List['pygame.event.Event'], _=None) -> None:
144144
"""
145145
for event in events:
146146
if event.type == pygame.KEYDOWN:
147-
# noinspection PyUnresolvedReferences
148147
if event.key == pygame.K_0:
149148
self._press(0)
150149
elif event.key == pygame.K_1:

pygame_menu/examples/other/scrollbar.py

-2
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ def make_world(width: int, height: int) -> 'pygame.Surface':
3636
for y in range(100, height, 200):
3737
if number_x in (0, max_x - 1) or number_y in (0, max_y - 1):
3838
# White circles to delimit world boundaries
39-
# noinspection PyArgumentList
4039
pygame.draw.circle(world, (255, 255, 255), (x, y), 100, 10)
4140
else:
42-
# noinspection PyArgumentList
4341
pygame.draw.circle(world, color, (x, y), 100, 10)
4442
if color[0] + 15 < 255:
4543
color[0] += 15

pygame_menu/font.py

-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ def get_font(name: FontType, size: int) -> '__font.Font':
124124
most_similar = 0
125125
most_similar_index = 0
126126
for i in range(len(system_fonts)):
127-
# noinspection PyArgumentEqualDefault
128127
sim = SequenceMatcher(None, system_fonts[i], font_name).ratio()
129128
if sim > most_similar:
130129
most_similar = sim

pygame_menu/sound.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def __init__(
181181
# noinspection PyBroadException
182182
try:
183183
# pygame < 1.9.5
184-
mixer_kwargs = {
184+
mixer_kwargs: Dict[str, Union[int, str]] = {
185185
'frequency': frequency,
186186
'size': size,
187187
'channels': channels,
@@ -275,7 +275,6 @@ def get_channel(self) -> 'mixer.Channel':
275275
276276
:return: Sound engine channel
277277
"""
278-
# noinspection PyArgumentList
279278
channel = mixer.find_channel() # force only available on pygame v2
280279
if self._uniquechannel: # If the channel is unique
281280
if self._channel is None: # If the channel has not been set
@@ -331,7 +330,6 @@ def set_sound(
331330

332331
# Load the sound
333332
try:
334-
# noinspection PyTypeChecker
335333
sound_data = mixer.Sound(file=sound_file)
336334
except pygame_error:
337335
if self._verbose:

pygame_menu/utils.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -271,21 +271,22 @@ def fill_gradient(
271271
if vertical:
272272
for line in range(y1, y2):
273273
color = (
274-
min(max(a[0] + (rate[0] * (line - y1)), 0), 255),
275-
min(max(a[1] + (rate[1] * (line - y1)), 0), 255),
276-
min(max(a[2] + (rate[2] * (line - y1)), 0), 255)
274+
int(min(max(a[0] + (rate[0] * (line - y1)), 0), 255)),
275+
int(min(max(a[1] + (rate[1] * (line - y1)), 0), 255)),
276+
int(min(max(a[2] + (rate[2] * (line - y1)), 0), 255))
277277
)
278278
fn_line(surface, color, (x1, line), (x2, line))
279279
else:
280280
for col in range(x1, x2):
281281
color = (
282-
min(max(a[0] + (rate[0] * (col - x1)), 0), 255),
283-
min(max(a[1] + (rate[1] * (col - x1)), 0), 255),
284-
min(max(a[2] + (rate[2] * (col - x1)), 0), 255)
282+
int(min(max(a[0] + (rate[0] * (col - x1)), 0), 255)),
283+
int(min(max(a[1] + (rate[1] * (col - x1)), 0), 255)),
284+
int(min(max(a[2] + (rate[2] * (col - x1)), 0), 255))
285285
)
286286
fn_line(surface, color, (col, y1), (col, y2))
287287

288288

289+
# noinspection PyUnusedLocal
289290
def format_color(
290291
color: Union[ColorInputType, Any],
291292
warn_if_invalid: bool = True
@@ -401,15 +402,13 @@ def load_pygame_image_file(image_path: str, **kwargs) -> 'pygame.Surface':
401402

402403
pil_invalid_exception = UnidentifiedImageError
403404
img_pil = Image.open(image_path)
404-
# noinspection PyTypeChecker
405+
# noinspection PyTypeChecker,PyUnusedLocal
405406
surface = pygame.image.fromstring(
406407
img_pil.tobytes(), img_pil.size, img_pil.mode).convert()
407-
408408
except (ModuleNotFoundError, ImportError):
409409
warn(f'Image file "{image_path}" could not be loaded, as pygame.error '
410410
f'is raised. To avoid this issue install the Pillow library')
411411
raise
412-
413412
except pil_invalid_exception:
414413
warn(f'The image "{image_path}" could not be loaded using Pillow')
415414
raise
@@ -442,7 +441,6 @@ def make_surface(
442441
'surface width and height must be equal or greater than zero'
443442
surface = pygame.Surface((int(width), int(height)), pygame.SRCALPHA, 32)
444443
if alpha and _ALPHA_CHANNEL[0]:
445-
# noinspection PyArgumentList
446444
surface = pygame.Surface.convert_alpha(surface)
447445
if fill_color is not None:
448446
fill_color = assert_color(fill_color)
@@ -602,7 +600,6 @@ def set_pygame_cursor(cursor: CursorInputType) -> None: # type: ignore
602600
"""
603601
try:
604602
if cursor is not None:
605-
# noinspection PyArgumentList
606603
pygame.mouse.set_cursor(cursor)
607604
except (pygame.error, TypeError):
608605
if PYGAME_V2:

pygame_menu/widgets/selection/highlight.py

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def __init__(
5555
def draw(self, surface: 'pygame.Surface', widget: 'pygame_menu.widgets.Widget') -> 'HighlightSelection':
5656
if self._border_width == 0:
5757
return self
58-
# noinspection PyArgumentList
5958
pygame.draw.rect(
6059
surface,
6160
self.color,

pygame_menu/widgets/widget/frame.py

-1
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,6 @@ def add_title_button(
506506

507507
# Draw style
508508
style_surface = make_surface(h, h, alpha=True)
509-
# noinspection PyArgumentList
510509
pygame.draw.polygon(style_surface, symbol_color, style_pos, border)
511510
btn.get_decorator().add_surface(0, 0, surface=style_surface, centered=True)
512511

pygame_menu/widgets/widget/menubar.py

-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ def _draw(self, surface: 'pygame.Surface') -> None:
250250

251251
# Draw backbox if enabled
252252
if self._backbox_visible():
253-
# noinspection PyArgumentList
254253
pygame.draw.rect(surface, self._backbox_background_color, self._backbox_rect, self._backbox_border_width)
255254
pygame.draw.polygon(surface, self._backbox_background_color, self._backbox_pos)
256255

0 commit comments

Comments
 (0)