ezmsg-org / ezmsg

Pure-Python DAG-based high-performance SHM-backed pub-sub and multi-processing pattern
https://ezmsg.readthedocs.io/en/latest/
MIT License
10 stars 5 forks source link

Inherited Unit does not inherit State correctly on python versions > 3.9 #134

Closed pperanich closed 3 days ago

pperanich commented 1 month ago

I recently ran into an odd bug where an inherited unit does not inherit the base classes STATE but does inherit it's SETTINGS. Importantly, this bug is only present in Python versions greater than 3.9. See below for a minimal example.

import ezmsg.core as ez

class BaseSettings(ez.Settings):
    y: int = 10

class BaseState(ez.State):
    x: int = 9

class BaseUnit(ez.Unit):
    SETTINGS: BaseSettings
    STATE: BaseState

    async def initialize(self) -> None:
        ez.logger.info(f"{self.SETTINGS=}, {self.STATE=}")

class ChildUnit(BaseUnit):
    async def initialize(self) -> None:
        ez.logger.info("In child")
        ez.logger.info(f"{self.SETTINGS=}, {self.STATE=}")
        return await super().initialize()

if __name__ == "__main__":
    ez.run(ChildUnit())

Output on 3.9:

2024-07-15 13:18:26.014 - pid: 35744 - TaskThread - INFO - initialize: In child
2024-07-15 13:18:26.014 - pid: 35744 - TaskThread - INFO - initialize: self.SETTINGS=BaseSettings(y=10), self.STATE=BaseState(x=9)
2024-07-15 13:18:26.014 - pid: 35744 - TaskThread - INFO - initialize: self.SETTINGS=BaseSettings(y=10), self.STATE=BaseState(x=9)
2024-07-15 13:18:26.016 - pid: 35744 - MainThread - INFO - run: All processes exited normally

Output on 3.10:

2024-07-15 13:18:25.996 - pid: 35743 - TaskThread - INFO - initialize: In child
2024-07-15 13:18:25.996 - pid: 35743 - TaskThread - INFO - initialize: self.SETTINGS=BaseSettings(y=10), self.STATE=State()
2024-07-15 13:18:25.996 - pid: 35743 - TaskThread - INFO - initialize: self.SETTINGS=BaseSettings(y=10), self.STATE=State()
2024-07-15 13:18:25.997 - pid: 35743 - MainThread - INFO - run: All processes exited normally
pperanich commented 3 days ago

Fixed by #135