11from abc import abstractmethod
2+ from collections .abc import Set
23from math import trunc
3- from typing import Generic
4+ from typing import Protocol
45
56from arcade .sprite import SpriteType , SpriteType_co
67from arcade .sprite .base import BasicSprite
78from arcade .types import IPoint , Point
89from arcade .types .rect import Rect
910
1011
11- class ReadOnlySpatialHash (Generic [SpriteType_co ]):
12- """
13- Read-only view of a SpatialHash.
12+ class ReadOnlySpatialHash (Protocol [SpriteType_co ]):
13+ """A read-only view of a :py:class:`.SpatialHash` which helps preserve safety.
14+
15+ This works like the read-only views of Python's built-in :py:class:`dict`
16+ and other types. As an every-day user, it means that the underlying
17+ `SpatialHash` may contain subclasses of the annotated type, but not
18+ superclasses.
1419
15- This is useful when the SpriteType is in covariant position.
20+ This ensures predicable behavior via type safety in cases where:
1621
17- See SpatialHash for more details.
22+ #. A spatial hash is annotated with a specific type
23+ #. It is then manipulated outside the original context with a broader type
24+
25+ Advanced users who want more information on the specifics should see the
26+ comments of :py:class:`~arcade.sprite_list.SpriteList`.
1827 """
1928
2029 @abstractmethod
21- def get_sprites_near_sprite (self , sprite : BasicSprite ) -> set [SpriteType_co ]:
30+ def get_sprites_near_sprite (self , sprite : BasicSprite ) -> Set [SpriteType_co ]:
2231 """
2332 Get all the sprites that are in the same buckets as the given sprite.
2433
@@ -28,7 +37,7 @@ def get_sprites_near_sprite(self, sprite: BasicSprite) -> set[SpriteType_co]:
2837 ...
2938
3039 @abstractmethod
31- def get_sprites_near_point (self , point : Point ) -> set [SpriteType_co ]:
40+ def get_sprites_near_point (self , point : Point ) -> Set [SpriteType_co ]:
3241 """
3342 Return sprites in the same bucket as the given point.
3443
@@ -38,12 +47,17 @@ def get_sprites_near_point(self, point: Point) -> set[SpriteType_co]:
3847 ...
3948
4049 @abstractmethod
41- def get_sprites_near_rect (self , rect : Rect ) -> set [SpriteType_co ]:
50+ def get_sprites_near_rect (self , rect : Rect ) -> Set [SpriteType_co ]:
4251 """
4352 Return sprites in the same buckets as the given rectangle.
4453
54+ .. tip:: Use :py:mod:`arcade.types.rect`'s helper functions to create
55+ rectangle objects!
56+
4557 Args:
46- rect: The rectangle to check (left, right, bottom, top)
58+ rect:
59+ The rectangle to check as a :py:class:`~arcade.types.rect.Rect`
60+ object.
4761 """
4862 ...
4963
0 commit comments