Nick Coghlan <ncogh...@gmail.com> added the comment:

Object instances don't get a __dict__ by default to save the space the pointer 
and dict instance would require. Most builtins are missing that pointer. It is 
also the main memory saving provided by the use of __slots__.

As far as AttributeError vs TypeError goes, the CPython core is actually pretty 
arbitrary as to which it raises (usually for historical reasons). In this case, 
AttributeError is technically correct, since object.__setattr__ *does* support 
writable attributes. It just so happens that a bare object() instance doesn't 
have any (since __doc__ is read-only).

I asked Guido ages ago about cleaning some of this up (due to some 
discrepancies between __enter__ and __exit__ and other special methods), but he 
was of the opinion that the backwards compatibility hassles weren't worth the 
gain in consistency.

----------
nosy: +ncoghlan

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue7659>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to