Skip to content

Commit b7dd2c3

Browse files
committed
Improve if/elif on return
1 parent 99751eb commit b7dd2c3

File tree

10 files changed

+25
-31
lines changed

10 files changed

+25
-31
lines changed

pygame_menu/_scrollarea.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ def get_border_size(self) -> Tuple2IntType:
592592
if isinstance(self._border_color, pygame_menu.BaseImage): # Image
593593
return self._border_tiles_size
594594
# Color
595-
if self._border_color is None:
595+
elif self._border_color is None:
596596
return 0, 0
597597
return self._border_width, self._border_width
598598

@@ -658,15 +658,13 @@ def get_scrollbar_thickness(self, orientation: str, visible: bool = True) -> int
658658
"""
659659
assert_orientation(orientation)
660660
assert isinstance(visible, bool)
661-
662661
if visible:
663662
total = 0
664663
for sbar in self._scrollbars:
665664
if sbar.get_orientation() == orientation and sbar.is_visible():
666665
total += sbar.get_thickness()
667666
return total
668-
669-
if orientation == ORIENTATION_HORIZONTAL:
667+
elif orientation == ORIENTATION_HORIZONTAL:
670668
return int(self._rect.height - self._view_rect.height)
671669
elif orientation == ORIENTATION_VERTICAL:
672670
return int(self._rect.width - self._view_rect.width)
@@ -702,7 +700,7 @@ def get_view_rect(self) -> 'pygame.Rect':
702700
return rect
703701

704702
# All scrollbars: the world is too large
705-
if self._world.get_height() > self._rect.height and self._world.get_width() > self._rect.width:
703+
elif self._world.get_height() > self._rect.height and self._world.get_width() > self._rect.width:
706704
for sbar in self._scrollbars:
707705
if not sbar.is_visible():
708706
continue

pygame_menu/baseimage.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ def scale(
652652
w, h = self.get_size()
653653
if width == 1 and height == 1:
654654
return self
655-
if not smooth or self._surface.get_bitsize() < 24:
655+
elif not smooth or self._surface.get_bitsize() < 24:
656656
self._surface = pygame.transform.scale(self._surface, (int(w * width), int(h * height)))
657657
else: # image bitsize less than 24 bits raises ValueError
658658
self._surface = pygame.transform.smoothscale(self._surface, (int(w * width), int(h * height)))
@@ -749,7 +749,7 @@ def rotate(self, angle: NumberType, auto_checkpoint: bool = True) -> 'BaseImage'
749749
assert isinstance(angle, NumberInstance)
750750
if angle == self._angle:
751751
return self
752-
if not self._rotated and auto_checkpoint:
752+
elif not self._rotated and auto_checkpoint:
753753
self.checkpoint()
754754
if self._rotated:
755755
self.restore()

pygame_menu/examples/other/maze.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1082,9 +1082,8 @@ def _dijkstra(
10821082
if current_node in visited_nodes:
10831083
if len(queue.show()) == 0:
10841084
return False
1085-
else:
1086-
priority, current_distance, current_node = queue.pop()
1087-
continue
1085+
_, current_distance, current_node = queue.pop()
1086+
continue
10881087

10891088
# Call to check neighbours of the current node
10901089
for neighbour in self._get_neighbours(current_node, n):

pygame_menu/menu.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ def select_widget(self, widget: Optional[Union['Widget', str]]) -> 'Menu':
10961096
w.select(False)
10971097
self._index = -1
10981098
return self
1099-
if isinstance(widget, str):
1099+
elif isinstance(widget, str):
11001100
widget = self.get_widget(widget)
11011101
assert isinstance(widget, Widget)
11021102
if not widget.is_selectable:
@@ -3669,7 +3669,7 @@ def _remove_submenu(
36693669
del self._submenus[menu]
36703670
self._update_after_remove_or_hidden(self._index)
36713671
return True
3672-
if recursive:
3672+
elif recursive:
36733673
for sm in self._submenus:
36743674
if sm._remove_submenu(menu, hook, recursive):
36753675
return True

pygame_menu/widgets/core/widget.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ def mouseover(
601601
while True:
602602
if len(prev) == 0:
603603
break
604-
if prev[0] == self._frame:
604+
elif prev[0] == self._frame:
605605
in_prev = True
606606
break
607607
prev = prev[2]
@@ -689,7 +689,7 @@ def _check_mouseover(
689689
return False
690690

691691
# If mouse out from window
692-
if event.type == pygame.ACTIVEEVENT and hasattr(event, 'gain'):
692+
elif event.type == pygame.ACTIVEEVENT and hasattr(event, 'gain'):
693693
if event.gain == 1:
694694
return False
695695
# Mouse is outside window
@@ -1702,7 +1702,6 @@ def _font_render_string(
17021702

17031703
# Replace tabs
17041704
text = text.replace('\t', ' ' * self._tab_size)
1705-
17061705
surface = self._font.render(text, self._font_antialias, color, bgcolor)
17071706
return surface
17081707

@@ -2028,9 +2027,6 @@ def _set_position_relative_to_frame(self, index: int = -1) -> 'Widget':
20282027
c, r, _ = self._frame.get_col_row_index()
20292028
self.set_col_row_index(c, r, index)
20302029
self._frame.update_indices()
2031-
else:
2032-
# raise ValueError(f'{self.get_class_id()} is not within a frame')
2033-
pass
20342030
return self
20352031

20362032
def set_position(self, x: NumberType, y: NumberType) -> 'Widget':
@@ -3124,6 +3120,7 @@ def _get_status(self) -> Tuple[Any, ...]:
31243120
data.append(ww._get_status())
31253121

31263122
# Append inner widgets if drop select
3123+
# noinspection PyUnresolvedReferences
31273124
if (isinstance(self, pygame_menu.widgets.DropSelect) and
31283125
hasattr(self, '_drop_frame') and
31293126
self._drop_frame is not None and

pygame_menu/widgets/widget/dropselect_multiple.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def __init__(
148148
placeholder_add_to_selection_box: bool = True,
149149
placeholder_selected: str = '{0} selected',
150150
scrollbar_color: ColorInputType = (235, 235, 235),
151-
scrollbar_cursor: CursorInputType = None,
151+
scrollbar_cursor: CursorInputType = None, # type: ignore
152152
scrollbar_shadow: bool = False,
153153
scrollbar_shadow_color: ColorInputType = (0, 0, 0),
154154
scrollbar_shadow_offset: int = 2,
@@ -173,7 +173,7 @@ def __init__(
173173
selection_option_active_font_color: ColorInputType = (0, 0, 0),
174174
selection_option_border_color: ColorInputType = (220, 220, 220),
175175
selection_option_border_width: int = 1,
176-
selection_option_cursor: CursorInputType = None,
176+
selection_option_cursor: CursorInputType = None, # type: ignore
177177
selection_option_font: Optional[FontType] = None,
178178
selection_option_font_color: ColorInputType = (0, 0, 0),
179179
selection_option_font_size: Optional[int] = None,
@@ -337,7 +337,7 @@ def _get_current_selected_text(self) -> str:
337337
f'string (List[str]=>str), not {type(o)} type ({o} returned)'
338338
return self._placeholder_selected.format(o)
339339

340-
raise ValueError('invalid selection placeholder format type')
340+
raise ValueError(f'invalid selection placeholder format type "{self._selection_placeholder_format}"')
341341

342342
def _get_selected_items_list_str(self) -> List[str]:
343343
"""

pygame_menu/widgets/widget/menubar.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,13 @@ def get_scrollbar_style_change(self, position: str) -> Tuple[int, Tuple2IntType]
270270
self._render()
271271
if not self._modify_scrollarea or not self.is_visible():
272272
return 0, (0, 0)
273-
if not self.fixed or self.is_floating():
273+
elif not self.fixed or self.is_floating():
274274
if self._style == MENUBAR_STYLE_ADAPTIVE:
275275
if position == POSITION_EAST:
276276
t = self._polygon_pos[4][1] - self._polygon_pos[2][1]
277277
return t, (0, -t)
278278
return 0, (0, 0)
279-
if position == POSITION_NORTH:
279+
elif position == POSITION_NORTH:
280280
return self._scrollbar_deltas[0]
281281
elif position == POSITION_EAST:
282282
return self._scrollbar_deltas[1]
@@ -298,7 +298,7 @@ def _render(self) -> Optional[bool]:
298298
return True
299299

300300
# Update box mode
301-
if menu_prev_condition:
301+
elif menu_prev_condition:
302302
self._box_mode = _MODE_CLOSE
303303
else:
304304
self._box_mode = _MODE_BACK

pygame_menu/widgets/widget/progressbar.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def _render(self) -> Optional[bool]:
229229
if not hasattr(self, '_progress_font'):
230230
return False
231231

232-
if not self._render_hash_changed(self._selected, self._title, self._visible, self.readonly, self._progress):
232+
elif not self._render_hash_changed(self._selected, self._title, self._visible, self.readonly, self._progress):
233233
return True
234234

235235
# Create basic title

pygame_menu/widgets/widget/rangeslider.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,9 @@ def _render(self) -> Optional[bool]:
654654
if not hasattr(self, '_font_range_value'):
655655
return False
656656

657-
if not self._render_hash_changed(self._selected, self._title, self._visible, self.readonly,
658-
self._range_values, self._slider_selected, self._value[0],
659-
self._value[1], self._scrolling, self._selected_mouse):
657+
elif not self._render_hash_changed(self._selected, self._title, self._visible, self.readonly,
658+
self._range_values, self._slider_selected, self._value[0],
659+
self._value[1], self._scrolling, self._selected_mouse):
660660
return True
661661

662662
# Create basic title

pygame_menu/widgets/widget/scrollbar.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,9 @@ def _render(self) -> Optional[bool]:
300300
if self._slider_rect is None:
301301
return
302302

303-
if not self._render_hash_changed(width, height, self._slider_rect.x, self._slider_rect.y,
304-
self.readonly, self._slider_rect.width, self._slider_rect.height,
305-
self.scrolling, self._mouseover, self._clicked):
303+
elif not self._render_hash_changed(width, height, self._slider_rect.x, self._slider_rect.y,
304+
self.readonly, self._slider_rect.width, self._slider_rect.height,
305+
self.scrolling, self._mouseover, self._clicked):
306306
return True
307307

308308
self._surface = make_surface(width, height)

0 commit comments

Comments
 (0)