Skip to content

Commit 4ac28d5

Browse files
osm3000Omar
andauthored
Fixing the SpatialHash issue 2186 (#2201)
Co-authored-by: Omar <osm3000@Omars-Laptop.local>
1 parent d0ca613 commit 4ac28d5

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

arcade/sprite_list/spatial_hash.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ class SpatialHash(Generic[SpriteType]):
3333

3434
def __init__(self, cell_size: int) -> None:
3535
# Sanity check the cell size
36+
if not isinstance(cell_size, int):
37+
raise TypeError("cell_size must be an int (integer)")
3638
if cell_size <= 0:
3739
raise ValueError("cell_size must be greater than 0")
38-
if not isinstance(cell_size, int):
39-
raise ValueError("cell_size must be an integer")
4040

4141
self.cell_size: int = cell_size
4242
"""How big each grid cell is on each side.

tests/unit/spritelist/test_spatial_hash.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ def test_create():
1010
assert sh.buckets_for_sprite == {}
1111
assert sh.count == 0
1212

13+
def test_incorrect_str_input():
14+
with pytest.raises(TypeError):
15+
sh = SpatialHash(cell_size="10")
16+
17+
def test_incorrect_inf_input():
18+
with pytest.raises(TypeError):
19+
sh = SpatialHash(cell_size=float("inf"))
1320

1421
def test_reset():
1522
sh = SpatialHash(cell_size=10)

0 commit comments

Comments
 (0)