Re:Problems once solved by a metaclass can be solved by __in...
by divbzero on Wednesday January 05, 2022 @11:14PM
(#29819294)
Parent and grandparent comments and their siblings provide a good summary of metaclasses. One of the best deep dives I’ve seen is this document [1] which is offline but still available through the Wayback Machine.
GP is right that metaclasses are rarely used and you’ll kind of know when you need them.
[1]: https://web.archive.org/web/20170805220114/http://www.cafepy...
Re:Problems once solved by a metaclass can be solved by __in...
by tshaddox on Wednesday January 05, 2022 @03:10PM
(#29814266)
Is this definition recursive? Meaning that classes whose instances are metaclasses are also metaclasses?
Re:Problems once solved by a metaclass can be solved by __in...
by dragonwriter on Wednesday January 05, 2022 @05:44PM
(#29816210)
Because metaclasses are classes, yes, classes whose instances are metaclasses are also classes whose instances are classes and thus are also metaclasses. But you could distinguish this subset of metaclasses as “metametaclasses” if you wanted to, to distinguish them from more general metaclasses just as metaclasses are distinguished from more general classes.
But AFAIK no one has come up with a distinct application for custom metametaclasses which would make having terminology to discuss them necessary or useful other than for entertainment.
Given the popularity of this construct for analogies and metaphorical comparisons, it should be noted that this is strictly literal. In Python classes are objects, and the classes whose instances are classes are called “metaclasses” (and they are subclasses of the class “type”.)