(continued from previous page) 20 ) super() .__setattr__ (name, value) def __delattr__ (self, name): 'Emulate _PyObject_GenericSetAttrWithDict() Objects/object.c ' cls=type(self) if hasattr(cls,'slot_names ') and name not in cls.slot_names: raise AttributeError( f' { type(self).__name__ !r} object has no attribute { name !r} ' ) super() .__delattr__ (name) classH (Object, metaclass =Type): 'Instance variables stored in slots ' slot_names=['x','y'] def __init__ (self, x, y): self.x =x self.y =y >>> from pprint import pp >>> pp(dict(vars(H))) {'__module__': '__main__', '__doc__': 'Instance variables stored in slots', 'slot_names': ['x', 'y'], '__init__': <function H.__init__ at 0x7fb5d302f9d0>, 'x': <Member 'x' of 'H'>, 'y': <Member 'y' of 'H'>} >>> h =H(10 ,20 ) >>> vars(h) {'_slotvalues': [10, 20]} >>> h .x =55 >>> vars(h) {'_slotvalues': [55, 20]} >>> h .xz Traceback (most recent call last): ... AttributeError: 'H' object has no attribute 'xz' Misspelled or unassigned attributes will raise an exception: When instances are created, they have a$_{slot_values}$ list where the attributes are stored: At this point, the metaclass has loaded member objects for x and y : To use the simulation in a real class, just inherit from Object and set the metaclass to Type :