There are two files with a chain of commands and a dict that dynamically collects all non-abstract commands.
logic.py
from abc import ABC, abstractmethod
class Command(ABC):
def __init__(self):
...
@abstractmethod
def run():
...
class Commands(dict):
def __init__(self):
import comm
breakpoint()
for cls in Command.__subclasses__():
names = self.split_camel_case(cls.__name__)
self[names] = cls
comm.py
from logic import Command
class TestCommand(Command):
...
Debugger output
> logic.py(28) __init__()
-> for cls in Command.__subclasses__():
(Pdb) comm.TestCommand.__mro__
(<class 'comm.TestCommand'>, <class 'logic.Command'>, <class 'abc.ABC'>, <class 'object'>)
(Pdb) Command.__subclasses__()
[]
By the time the Commands.__init__()
is called the base class Command
is already defined. The module comm
is imported and the subclass TestCommand
is defined too. But the list returned by Command.__subclass__()
is empty.
Tell me please, what am I missing?