Skip to content

Commit f61c9b1

Browse files
committed
Improve implicit returns
1 parent e48ea5c commit f61c9b1

File tree

10 files changed

+25
-16
lines changed

10 files changed

+25
-16
lines changed

pygame_menu/examples/other/maze.py

+4-3
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/widgets/core/widget.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ class Widget(Base):
233233
_check_mouseleave_call_render: bool
234234
_col_row_index: Tuple3IntType
235235
_ctrl: 'Controller'
236-
_cursor: CursorType
236+
_cursor: CursorType # type: ignore
237237
_decorator: 'Decorator'
238238
_default_value: Any
239239
_draw_callbacks: Dict[str, Callable[['Widget', Optional['pygame_menu.Menu']], Any]]
@@ -1255,14 +1255,15 @@ def apply(self, *args) -> Any:
12551255
"""
12561256
self.scroll_to_widget(scroll_parent=False)
12571257
if self.readonly:
1258-
return
1258+
return None
12591259
elif self._onreturn:
12601260
args = list(args) + list(self._args)
12611261
try:
12621262
args.insert(0, self.get_value())
12631263
except ValueError:
12641264
pass
12651265
return self._onreturn(*args, **self._kwargs)
1266+
return None
12661267

12671268
def change(self, *args) -> Any:
12681269
"""
@@ -3137,7 +3138,7 @@ def _get_status(self) -> Tuple[Any, ...]:
31373138
)
31383139

31393140
# Starting data
3140-
data = [cls_name, geom, bool_status]
3141+
data: List[Any] = [cls_name, geom, bool_status]
31413142

31423143
# Append inner widgets if frame and not menu
31433144
if isinstance(self, pygame_menu.widgets.Frame):

pygame_menu/widgets/widget/dropselect.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class DropSelect(Widget):
117117
_placeholder: str
118118
_placeholder_add_to_selection_box: bool
119119
_scrollbar_color: ColorType
120-
_scrollbar_cursor: CursorType
120+
_scrollbar_cursor: CursorType # type: ignore
121121
_scrollbar_shadow: bool
122122
_scrollbar_shadow_color: ColorType
123123
_scrollbar_shadow_offset: int
@@ -140,7 +140,7 @@ class DropSelect(Widget):
140140
_selection_infinite: bool
141141
_selection_option_border_color: ColorType
142142
_selection_option_border_width: int
143-
_selection_option_cursor: CursorType
143+
_selection_option_cursor: CursorType # type: ignore
144144
_selection_option_font_style: Dict[str, Any]
145145
_selection_option_left_space: bool
146146
_selection_option_left_space_height_factor: float
@@ -873,9 +873,9 @@ def _down(self) -> None:
873873
Move current selection down.
874874
"""
875875
if self.readonly:
876-
return
876+
return None
877877
elif len(self._items) == 0:
878-
return
878+
return None
879879
elif not self.active:
880880
return self._toggle_drop()
881881
elif self._index == -1:
@@ -887,19 +887,20 @@ def _down(self) -> None:
887887
prev = self._index
888888
new = max(0, self._index - 1)
889889
if prev == new:
890-
return
890+
return None
891891
self.set_value(new)
892892
self.change(*self._items[self._index][1:])
893893
self._sound.play_key_add()
894+
return None
894895

895896
def _up(self) -> None:
896897
"""
897898
Move current selection up.
898899
"""
899900
if self.readonly:
900-
return
901+
return None
901902
elif len(self._items) == 0:
902-
return
903+
return None
903904
elif not self.active:
904905
return self._toggle_drop()
905906
elif self._index == -1:
@@ -911,10 +912,11 @@ def _up(self) -> None:
911912
prev = self._index
912913
new = min(self._index + 1, len(self._items) - 1)
913914
if prev == new:
914-
return
915+
return None
915916
self.set_value(new)
916917
self.change(*self._items[self._index][1:])
917918
self._sound.play_key_add()
919+
return None
918920

919921
def set_value(self, item: Union[str, int]) -> None:
920922
"""

pygame_menu/widgets/widget/image.py

+1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ def _render(self) -> Optional[bool]:
167167
if not self._render_hash_changed(self._visible):
168168
return True
169169
self.force_menu_surface_update()
170+
return None
170171

171172
def update(self, events: EventVectorType) -> bool:
172173
self.apply_update_callbacks(events)

pygame_menu/widgets/widget/label.py

+1
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ def _render(self) -> Optional[bool]:
332332
)
333333

334334
self.force_menu_surface_update()
335+
return None
335336

336337
def update(self, events: EventVectorType) -> bool:
337338
# If generator is not None

pygame_menu/widgets/widget/progressbar.py

+1
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ def _render(self) -> Optional[bool]:
268268

269269
# Finals
270270
self.force_menu_surface_update()
271+
return None
271272

272273
def update(self, events: EventVectorType) -> bool:
273274
self.apply_update_callbacks(events)

pygame_menu/widgets/widget/rangeslider.py

+1
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ def _render(self) -> Optional[bool]:
786786

787787
# Finals
788788
self.force_menu_surface_update()
789+
return None
789790

790791
def _get_pos_range(self, value: NumberType, surface: Optional['pygame.Surface'] = None) -> int:
791792
"""

pygame_menu/widgets/widget/selector.py

+1
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ def _render(self) -> Optional[bool]:
320320
self._apply_transforms()
321321
self._rect.width, self._rect.height = self._surface.get_size()
322322
self.force_menu_surface_update()
323+
return None
323324

324325
def get_index(self) -> int:
325326
"""

pygame_menu/widgets/widget/textinput.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ def _render(self) -> Optional[bool]:
530530

531531
# Force Menu update
532532
self.force_menu_surface_update()
533+
return None
533534

534535
def _render_selection_box(self, force: bool = False) -> None:
535536
"""
@@ -1559,7 +1560,6 @@ def update(self, events: EventVectorType) -> bool:
15591560
self._clock.tick(60)
15601561

15611562
# Check mouse pressed
1562-
# noinspection PyArgumentList
15631563
mouse_left, mouse_middle, mouse_right = pygame.mouse.get_pressed()
15641564
self._mouse_is_pressed = (mouse_left or mouse_right or mouse_middle) and self._mouse_enabled
15651565

@@ -1609,7 +1609,6 @@ def update(self, events: EventVectorType) -> bool:
16091609
if any(pygame.key.get_mods() & mod == mod for mod in CTRL_KMOD):
16101610
# If test, disable CTRL
16111611
if 'test' in event.dict and event.dict['test']:
1612-
# noinspection PyArgumentList
16131612
pygame.key.set_mods(pygame.KMOD_NONE)
16141613

16151614
# Ctrl+C copy

pygame_menu/widgets/widget/toggleswitch.py

+1
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ def _render(self) -> Optional[bool]:
349349

350350
# Finals
351351
self.force_menu_surface_update()
352+
return None
352353

353354
def _left(self) -> None:
354355
"""

0 commit comments

Comments
 (0)