benmoran56 / esper

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

mypy `get_components` gives "object" type #77

Closed Felecarpp closed 1 year ago

Felecarpp commented 1 year ago

Describe the bug mypy show an error message in process methods because get_components gives "object" type.

To Reproduce

from dataclasses import dataclass
from esper import World, Processor

@dataclass
class Position:
    x: int = 0

@dataclass
class Velocity:
    x: int

class MovementProcessor(Processor):
    def process(self) -> None:
        for ent, (pos, vel) in self.world.get_components(Position, Velocity):
            pos.x += vel.x

world = World()
world.add_processor(MovementProcessor())
ent = world.create_entity(Position(), Velocity(1))
world.process()
pos = world.try_component(ent, Position)
if pos:
    print(f"player is now {pos.x}")
$ python esper_mypy_test.py 
player is now 1
$ mypy esper_mypy_test.py 
esper_mypy_test.py:18: error: "object" has no attribute "x"  [attr-defined]
Found 1 error in 1 file (checked 1 source file)

Expected behavior mypy should find the components types from get_components

Development environment:

Additional context possibly related to #60

Felecarpp commented 1 year ago

Sorry, after rereading, that is exactly the same issue as #60.