Skip to content

Commit 8d06749

Browse files
Copiloteruvanos
andcommitted
Address review feedback: use Ellipsis sentinel, add type hints, use catch_warnings in tests
Co-authored-by: eruvanos <9437863+eruvanos@users.noreply.github.com>
1 parent 570df7a commit 8d06749

2 files changed

Lines changed: 25 additions & 17 deletions

File tree

arcade/gui/widgets/layout.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
W = TypeVar("W", bound="UIWidget")
1616

17-
_NO_EXPLICIT_SIZE = object()
17+
_NO_EXPLICIT_SIZE = ...
1818
"""Sentinel value to detect when width/height was not explicitly provided by the user."""
1919

2020

@@ -31,9 +31,9 @@ def _warn_if_size_hint_overrides_fixed_size(
3131
3232
Args:
3333
class_name: Name of the layout class, used in the warning message.
34-
width: The width argument passed to __init__, or ``_NO_EXPLICIT_SIZE`` if
34+
width: The width argument passed to __init__, or ``...`` if
3535
width was not explicitly provided.
36-
height: The height argument passed to __init__, or ``_NO_EXPLICIT_SIZE`` if
36+
height: The height argument passed to __init__, or ``...`` if
3737
height was not explicitly provided.
3838
size_hint: The size_hint argument passed to __init__.
3939
"""
@@ -114,8 +114,8 @@ def __init__(
114114
*,
115115
x: float = 0,
116116
y: float = 0,
117-
width: float = _NO_EXPLICIT_SIZE,
118-
height: float = _NO_EXPLICIT_SIZE,
117+
width: float | type(...) = _NO_EXPLICIT_SIZE,
118+
height: float | type(...) = _NO_EXPLICIT_SIZE,
119119
children: Iterable[UIWidget] = tuple(),
120120
size_hint=(1, 1),
121121
size_hint_min=None,

tests/unit/gui/test_layout_size_hint_warning.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
"""Tests that layouts warn when explicit width/height conflicts with active size_hint."""
2+
import warnings
3+
24
import pytest
35

46
from arcade.gui import UIBoxLayout
@@ -19,14 +21,16 @@ def test_anchor_layout_warns_when_height_given_with_default_size_hint(window):
1921

2022
def test_anchor_layout_no_warning_when_size_hint_none(window):
2123
"""UIAnchorLayout should not warn when size_hint=None is explicitly set."""
22-
# No warning expected
23-
UIAnchorLayout(width=500, height=500, size_hint=None)
24+
with warnings.catch_warnings():
25+
warnings.simplefilter("error")
26+
UIAnchorLayout(width=500, height=500, size_hint=None)
2427

2528

2629
def test_anchor_layout_no_warning_when_no_explicit_size(window):
2730
"""UIAnchorLayout should not warn when width/height are not explicitly given."""
28-
# No warning expected
29-
UIAnchorLayout(size_hint=(1, 1))
31+
with warnings.catch_warnings():
32+
warnings.simplefilter("error")
33+
UIAnchorLayout(size_hint=(1, 1))
3034

3135

3236
def test_anchor_layout_no_warning_when_size_hint_x_none(window):
@@ -57,14 +61,16 @@ def test_box_layout_warns_when_height_given_with_default_size_hint(window):
5761

5862
def test_box_layout_no_warning_when_size_hint_none(window):
5963
"""UIBoxLayout should not warn when size_hint=None is explicitly set."""
60-
# No warning expected
61-
UIBoxLayout(width=200, height=200, size_hint=None)
64+
with warnings.catch_warnings():
65+
warnings.simplefilter("error")
66+
UIBoxLayout(width=200, height=200, size_hint=None)
6267

6368

6469
def test_box_layout_no_warning_when_no_explicit_size(window):
6570
"""UIBoxLayout should not warn when width/height are not explicitly given."""
66-
# No warning expected
67-
UIBoxLayout(size_hint=(0, 0))
71+
with warnings.catch_warnings():
72+
warnings.simplefilter("error")
73+
UIBoxLayout(size_hint=(0, 0))
6874

6975

7076
def test_grid_layout_warns_when_width_given_with_default_size_hint(window):
@@ -81,14 +87,16 @@ def test_grid_layout_warns_when_height_given_with_default_size_hint(window):
8187

8288
def test_grid_layout_no_warning_when_size_hint_none(window):
8389
"""UIGridLayout should not warn when size_hint=None is explicitly set."""
84-
# No warning expected
85-
UIGridLayout(width=200, height=200, size_hint=None)
90+
with warnings.catch_warnings():
91+
warnings.simplefilter("error")
92+
UIGridLayout(width=200, height=200, size_hint=None)
8693

8794

8895
def test_grid_layout_no_warning_when_no_explicit_size(window):
8996
"""UIGridLayout should not warn when width/height are not explicitly given."""
90-
# No warning expected
91-
UIGridLayout(size_hint=(0, 0))
97+
with warnings.catch_warnings():
98+
warnings.simplefilter("error")
99+
UIGridLayout(size_hint=(0, 0))
92100

93101

94102
def test_warning_message_includes_class_name(window):

0 commit comments

Comments
 (0)