The Python docs say that the metaclass of a class can be any callable. All the examples I see use a class. Why not use a function? It's callable, and fairly simple to define. But it isn't working, and I don't understand why.
Here's my code:
class Foo(object):
def __metaclass__(name, base, dict):
print('inside __metaclass__(%r, ...)' % name)
return type(name, base, dict)
print(Foo.__metaclass__)
class Bar(Foo):
pass
print(Bar.__metaclass__)
Here's the output:
inside __metaclass__('Foo', ...)
<unbound method Foo.__metaclass__>
<unbound method Bar.__metaclass__>
The metaclass method is defined for both the parent and child classes. Why is it only getting called for the parent? (Yes, I tried using the classmethod and staticmethod decorators for my metaclass, neither works. Yes, this might seem to be a dup of Metaclass not being called in subclasses but they are a class, not a function, as a metaclass.)