Python __new__ metaclass behavior with inheritance
问题 I have two questions regarding the behavior of running the below code. Why is __new__ even being called without instantiating an object? I thought __new__ controlled the creation of a new instance . Next, why does delattr raise an AttributeError when hasattr returns True for size ? class ShapeBase(type): def __new__(cls, name, bases, attrs): rv = super(ShapeBase, cls).__new__(cls, name, bases, attrs) parents = [base for base in bases if isinstance(base, ShapeBase)] # don't do anything unless