Search code examples
pythonclassobjectterminologymetaclass

Are there any conventional terms for non-metaclass classes and for non-class objects in Python?


There are three levels of objects in Python:

  • a metaclass is an object x such that isinstance(x, type) and issubclass(x, type) evaluates to True;
  • a class is an object x such that isinstance(x, type) evaluates to True. So this includes metaclasses;
  • an object. So this includes classes.

Thus the relation between these three sets is proper inclusion: metaclasses ⊂ classes ⊂ objects.

Example:

class M(type): pass
class C(metaclass=M): pass
o = C()
Name Metaclass Class Object
M True True True
C False True True
o False False True

Are there any conventional terms for non-metaclass classes (e.g. C in the example) and for non-class objects (e.g. o in the example)?

This terminology issue is frequent for sets related by inclusion. For instance, numbers have the following relation: natural numbers ⊂ integers ⊂ rational numbers ⊂ real numbers ⊂ complex numbers. The terms for non-natural integers are negative integers and for non-rational real numbers are irrational numbers. However I am not aware of any terms for non-integer rational numbers nor for non-real complex numbers.


Solution

  • To start with, I don't think it would be much useful to try and assert this classification.As there are no "3 levels", as one can create a "meta meta class" - type itself being the metaclass for ordinary metaclasses is the "metametaclass" for a class.

    And then, come specifically to your question, no, there are no widely used single terms for a "non class object", or a "non metaclass class". However, all times when we are talking of things that apply to "objects", those will work with all kinds of objects, regardless of they being classes (or metaclasses) - that is the practical meaning of these also being objects.

    For example, if one says "an attribute assignment to an object will end up being representd by an entry in that object's __dict__ attribute" - that is valid for all three kinds of object you list. And so on for most things and on the few occasions that that you have to exclude classes or metaclasses from whatever concept is being presented, you can just be explicit about it: "You can conversely create an entry in an object's __dict__ and have that entry work as if an assigned attributes. That however does not work with classes, since their __dict__ is a special proxy instance which does not allow assignments to ensure all special attribute assignments are reflected in the proper class' slots."

    As such, just as you do with numbers, you can just mention "non-class objects" or "non-metaclass classes" in the few occasions that is needed.