class dict of subtyped types
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 "<stdin>", 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', 'has_key', 'items', 'keys', 'values']
Other dict attributes are missing as well in the dict-proxy. Is this intentional? Thomas
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 "<stdin>", 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', 'has_key', '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. --Guido van Rossum (home page: http://www.python.org/~guido/)
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 "<stdin>", 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', 'has_key', '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
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.
Yes, but you have to use the attribute notation: INT.foo = ... this is trapped so that certain magic happens automatically when you set attributes that override operators, e.g. INT.__add__ = lambda ... --Guido van Rossum (home page: http://www.python.org/~guido/)
participants (2)
-
Guido van Rossum -
Thomas Heller