I have a set of plugins that inherit from a metaclass. the metaclasss is defined like so:
from abc import ABC, abstractmethod
class MetaReader(ABC):
def __init__(self, arg1, arg2, **kwargs):
...
and the subclass like so:
from utils.MetaReader import MetaReader
class ABF2Reader(MetaReader):
...
This works, as far as I can tell, and I can instantiate classes and use them as intended. However, at some points I need to load these classes as plugins without instantiating them, and when I do, I need to check their subclass against the proper metaclass to know what to do with them when loaded. And there, I get some weird results:
from utils.MetaReader import MetaReader
from plugins.datareaders.ABF2Reader import ABF2Reader
print(type(reader)) #reader is an instance of ABF2Reader
print(type(MetaReader)) #MetaReader is just the metaclass, not instantiated
print(type(ABF2Reader)) #Just the subclass, not instantiated
prints:
<class 'plugins.datareaders.ABF2Reader.ABF2Reader'>
<class 'abc.ABCMeta'>
<class 'abc.ABCMeta'>
The type for reader
is what I expect: it’s an instance of ABF2Reader. But the types for the other two are not. type(MetaReader)
is also fine, but I expect type(ABF2Reader)
to give me <class 'MetaReader'>, not
<class ‘abc.ABCMeta’>`
Clearly I am using metaclasses wrong. Can someone shed some light on where I am screwing this up?