Generic metaclass to keep track of subclasses?
问题 I'm trying to writing a generic metaclass for tracking subclasses Since I want this to be generic, I didn't want to hardcode any class name within this metaclass, therefore I came up with a function that generates the proper metaclass, something like: def make_subtracker(root): class SubclassTracker(type): def __init__(cls, name, bases, dct): print('registering %s' % (name,)) root._registry.append(cls) super(SubclassTracker, cls).__init__(name, bases, dct) return SubclassTracker This way I