I'm implementing a function that returns an object from the appropriate subclass. If I move SubClass
from base.py
, no subclasses appear for __subclasses__
. Are they required to be in the same file?
Perhaps the fact that I'm never importing directly subclass.py
hides the subclass from python? What can I do? I have even checked the attribute __mro__
and get_subclass
points to the right class.
# project/main.py
from project.src.base import get_subclass
obj = get_subclass(cls,name) # Returns an object of a subclass of cls
# project/src/subclass.py
from project.src.base import BaseClass
class SubClass(BaseClass):
pass
# project/src/base.py
def get_subclass(cls,name):
subclss = cls.__subclasses__ # This is returning an empty list
pass
class BaseClass(object):
pass