[Python-Dev] class dict of subtyped types (original) (raw)

Thomas Heller thomas.heller@ion-tof.com
Mon, 29 Oct 2001 21:09:48 +0100


From: "Guido van Rossum" <guido@python.org>

> C:>python > Python 2.2b1+ (#25, Oct 19 2001, 14:30:05) [MSC 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> class INT(int): pass > ... > >>> INT.dict > <dict-proxy object at 0x00769680> > >>> INT.dict.update > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: 'dict-proxy' object has no attribute 'update' > >>> dir(INT.dict) > ['class', 'contains', 'delattr', 'getattribute', 'getitem', 'hash' > , 'init', 'iter', 'len', 'new', 'reduce', 'repr', 'setattr', ' > str', 'copy', 'get', 'haskey', 'items', 'keys', 'values'] > >>> > > Other dict attributes are missing as well in the dict-proxy. > Is this intentional?

The dict-proxy type is intended to provide a read-only proxy, so the dict-proxy is consciously lacking the update, clear, popitem and setdefault methods. It also seems to be missing the comparison operations; that's an oversight. But adding attributes to the INT class above after creation is allowed, I hope? At least it currently works.

Thomas