4 ms·
> What classes are to instances, metaclasses are to classes. Given the popularity of this construct for analogies and metaphorical comparisons, it should be no
by dragonwriter 5y ago
> What classes are to instances, metaclasses are to classes.
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”.)
- tshaddox 5y agoIs this definition recursive? Meaning that classes whose instances are metaclasses are also metaclasses?
- xapata 5y agoCheck the type of `type` in Python ;-)
- dragonwriter 5y agoBecause 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.
- deleted 5y ago[deleted]
- divbzero 5y agoParent 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.com/article/python_types_and_objects/python_types_and_objects.html https://web.archive.org/web/20170805220114/http://www.cafepy...