[Python-Dev] q about __dict__
Tue, 13 Aug 2002 17:03:21 +0400
Hi, Guido, other python developers and other subscribers :-)
Anybody, please explain me, is this a bug? :
=== begin ===
raise Exception, "Please, do not touch me!"
self.__dict__ = Dict()
A().x = 12
=== end ===
doesn't raise Exception, i. e. my __setitem__ function is not called.
Patching that is simple: in Objects/classobject.c need to replace
PyDict_SetItem -> PyObject_SetItem
PyDict_GetItem -> PyObject_GetItem
PyDict_DelItem -> PyObject_DelItem
and maybe something else (not much).
Overhead is minimal, and as bonus python gets ability of assigning
object of any type (not inherited from dict) to __dict__.
Somethimes I want to write strange classes, for example, class with
ordered attributes. I know, that it is possibe to implement this
redefining class attributes __setattr__, etc., but setting __dict__
Thanks for reading this letter till the end ;-)
mailto: Stepan Koltsov <firstname.lastname@example.org>