benmoran56 / esper

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

Typing of world under the processor class #75

Closed menganha closed 1 year ago

menganha commented 1 year ago

Hello,

I was wondering why the world instance reference under the Processor class is not typed, i.e.,

`class Processor: """Base class for all Processors to inherit from.

Processor instances must contain a `process` method. Other than that,
you are free to add any additional methods that are necessary. The process
method will be called by each call to :py:class:`World.process`, so you will
generally want to iterate over entities with one (or more) calls to the
appropriate world methods there, such as::

    for ent, (rend, vel) in self.world.get_components(Renderable, Velocity):
         your_code_here()
"""

priority = 0
world = _Any

def process(self, *args, **kwargs):
    raise NotImplementedError`

with this set up I cannot get smart autocompletion on the world reference when working on a processor. (I'm using pycharm 2022.2.3)

I use my own Processor subclass, in which I've added the type information as

world: World = None

and the completion is working fine.

I haven't found any issue so far with this approach. Is there something I'm not considering? Why was the idea behind assigning it to the generic type Any?

Regards, Alvaro

benmoran56 commented 1 year ago

Hi Alvaro,

Thanks for opening the ticket. I think this code was written when Python 3.6 was still supported, and forward Typing definition wasn't as well supported. I actually just pushed out a new point release that updates this. It should work better with PyCharm (and other IDEs) now. Let me know if you still have any issues after updating to 2.4, but I'll close this as now.

menganha commented 1 year ago

Many thanks.! I just tried the new release and the autocompletion is working flawlessly.

benmoran56 commented 1 year ago

Great, thanks for confirming.