>>> a = object()
>>> a.x = 5
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'object' object has no attribute 'x'
>>> b = lambda:0
>>> b.x = 5
instances of types defined in C don't have a __dict__ attribute by
Return a new featureless object. object is a base for all classes. It has the methods that are common to all instances of Python classes. This function does not accept any arguments.
Note: object does not have a
__dict__, so you can’t assign arbitrary attributes to an instance of the object class.
Thus, the reason you cannot add arbitrary attributes to your
object() appears to be because of the fact that
object() instances do not have an implementation of the
__dict__ method, no because
object() instances are immutable.
Another interesting thing, but perhaps not relevant to the discussion at hand, is that while an instance of object may not have a
__dict__ implementation, the
object class itself does:
>>> hasattr(object, '__dict__') True
As for why this is, I cannot find any exact for reasons for why
object() doesn't have a
__dict__. Is is probably because - as @tdelany has already hit on in the comments - it is an implementation detail. If you really want a definitive answer, you should ask Guido himself.