benmoran56 / esper

An ECS (Entity Component System) for Python
MIT License
537 stars 67 forks source link

Fix get_components typing #78

Closed Felecarpp closed 1 year ago

Felecarpp commented 1 year ago

method implementation is not modified in this commit

fix #60 and #77 : get_components now return different component types

mypy esper and pytest tests tested with python 3.11.2

check issue #77 is fixed

from esper import World

class Position:
    def __init__(self) -> None:
        self.x = 0

class Velocity:
    def __init__(self, x: int) -> None:
        self.x = x

world = World()
ent = world.create_entity(Position(), Velocity(1))
for ent, (pos, vel) in world.get_components(Position, Velocity):
    pos.x += "z"
$ mypy esper_mypy_test.py 
esper_mypy_test.py:17: error: Unsupported operand types for + ("int" and "str")  [operator]
Found 1 error in 1 file (checked 1 source file)
benmoran56 commented 1 year ago

Thanks for this.

I think four components is a reasonable number of components to account for. It's already bordering on being too messy, so I am happy with this.