[Python-Dev] Language reference updated for metaclasses (original) (raw)

Mark Shannon mark at hotpy.org
Tue Jun 5 10:34:37 CEST 2012


Steven D'Aprano wrote:

On Tue, Jun 05, 2012 at 10:20:58AM +0300, Eli Bendersky wrote:

Still, instance of type()" is a bit too cryptic for mere mortals, IMHO. I think that if somebody finds "instance of type" too cryptic, they won't have any chance at all to understand metaclasses. Personally, I think there is a lot confusing about metaclasses, but the idea that classes are instances (objects) is not one of them.

One thing that is confusing is that the metaclass parameter in class creation is not the metaclass (class of the class), but the class factory. For example:

def silly(*args): print(*args) return int

class C(metaclass=silly): def m(self): pass

C () {'m': <function C.m at 0xb721fe14>, 'qualname': 'C', 'module': 'main'}

print(C) int

In this example the metaclass (ie the class of C) is type (C is int), even though the declared metaclass is 'silly'.

I assume it is too late to change the name of the 'metaclass' keyword to 'factory', but we could use that terminology in the docs.

Cheers, Mark



More information about the Python-Dev mailing list