I am trying to fill in a gap in my understanding of how Python objects and classes work.
A bare object instance does not support attribute assignment in any way:
> object().a = 5
# or
> setattr(object(), 'a', 5)
AttributeError: 'object' object has no attribute 'a'
I assume that this is because a bare object instance does not possess an __dict__ attribute:
> '__dict__' in dir(object())
False
However a bare object instance does have a defined __setattr__ attribute, so this is a bit confusing to me:
> '__setattr__' in dir(object())
True
An instance of a regular empty class on the other hand has full ability of attribute assignment:
class B(object):
pass
> B().a = 5
> setattr(B(), 'a', 5)
My question is: what inherent difference between an object instance and a class B(object) instance allows the latter to have assignable attributes, if B inherits directly from object?