Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

check_for_collision_with_list does not return the right SpriteType #2576

Copy link
Copy link
@sjrd

Description

@sjrd
Issue body actions

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

def check_for_collision_with_list(
sprite: SpriteType,
sprite_list: SpriteList,
method: int = 0,
) -> List[SpriteType]:

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:

def check_for_collision_with_lists(
sprite: BasicSprite,
sprite_lists: Iterable[SpriteList[SpriteType]],
method=1,
) -> List[SpriteType]:

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.