Skip to content

Commit 3c326c1

Browse files
committed
Improve typing and consistent returns
1 parent 7a61f59 commit 3c326c1

27 files changed

+83
-89
lines changed

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ pygame-menu-ce
1414
:target: https://opensource.org/licenses/MIT
1515
:alt: License MIT
1616

17-
.. image:: https://img.shields.io/badge/python-3.7+-red.svg
17+
.. image:: https://img.shields.io/badge/python-3.8+-red.svg
1818
:target: https://www.python.org/downloads
19-
:alt: Python 3.7+
19+
:alt: Python 3.8+
2020

2121
.. image:: https://badge.fury.io/py/pygame-menu.svg
2222
:target: https://pypi.org/project/pygame-menu

build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import sys
1212

1313
assert len(sys.argv) == 2, 'Argument is required, usage: build.py pip/twine'
14-
mode = sys.argv[1].strip()
14+
mode: str = sys.argv[1].strip()
1515

1616
if mode == 'pip':
1717
if os.path.isdir('dist'):

pygame_menu/_decorator.py

Lines changed: 20 additions & 21 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 13 additions & 14 deletions
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

Lines changed: 0 additions & 1 deletion
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/maze.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,6 @@ def _update_square(self, row: int, column: int) -> None:
10271027
:param column: Column number
10281028
:return:
10291029
"""
1030-
# noinspection PyArgumentList
10311030
pygame.display.update(
10321031
(self._margin + self._width) * column + self._margin + self._offset[0],
10331032
(self._margin + self._height) * row + self._margin + self._offset[1],
@@ -1234,6 +1233,8 @@ def _xfs(self, mazearray: _MazeType, start_point: _Point2, goal_node: _Point2, x
12341233
current_node = mydeque.pop()
12351234
elif x == 'b':
12361235
current_node = mydeque.popleft()
1236+
else:
1237+
return False
12371238

12381239
# noinspection PyUnboundLocalVariable
12391240
if current_node == goal_node:
@@ -1248,10 +1249,10 @@ def _xfs(self, mazearray: _MazeType, start_point: _Point2, goal_node: _Point2, x
12481249
if path_node == start_point:
12491250
return True
12501251

1251-
if mazearray[current_node[0]][current_node[1]].nodetype == 'wall':
1252+
elif mazearray[current_node[0]][current_node[1]].nodetype == 'wall':
12521253
continue
12531254

1254-
if current_node not in visited_nodes:
1255+
elif current_node not in visited_nodes:
12551256
visited_nodes.add(current_node)
12561257
mazearray[current_node[0]][current_node[1]].update(is_visited=True)
12571258
self._draw_square(mazearray, current_node[0], current_node[1])

pygame_menu/examples/other/scrollbar.py

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 1 deletion
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

0 commit comments

Comments
 (0)