Description
Hi! First, thanks a lot for this library. I am using it this semester as a teaching vehicle at the university level. It is really nice. Unlike the platformer tutoriel, I actually mandate using mypy in strict mode for all students' code.
It seems to me that the type signature of arcade.check_for_collision_with_list
is incorrect. It is defined as
arcade/arcade/sprite_list/collision.py
Lines 189 to 193 in 5743504
You can see that it returns a
List[SpriteType]
, where SpriteType
is the type of the single sprite
. However, in practice it returns elements of the given sprite_list
.
Because of that, when trying to use it as follows:
enemies: arcade.SpriteList[Enemy]
for enemy in arcade.check_for_collision_with_list(weapon, self.enemies):
enemy.hit_by_weapon() # method only available on Enemy; not on Sprite
return
I get a type error telling me hit_by_weapon
is not a method of Sprite
.
I think the correct signature should be
def check_for_collision_with_list(
sprite: BasicSprite,
sprite_list: SpriteList[SpriteType],
method: int = 0,
) -> List[SpriteType]:
Workaround
Use arcade.check_for_collision_with_lists(self, [self.enemies])
instead. For some reason the alternative method with an Iterable[SpriteList]
has the correct type:
arcade/arcade/sprite_list/collision.py
Lines 249 to 253 in 5743504
Activity