[Python-Dev] Evil setattr hack

Greg Ewing greg@cosc.canterbury.ac.nz
Mon, 14 Apr 2003 13:17:14 +1200 (NZST)


Guido:

> one approach would be special cases in PyObject_GenericSetAttr,
> I guess.

Before using a hack like that, it might be better to think about what
the real problem is.

Seems to me the problem in general is that there's no way to prevent a
class which overrides a method from having a superclass version of
that method called through a back door. Which means you can't rely on
method overriding to *restrict* what can be done to an object.

So a proper fix would require either:

(1) Providing some way for objects to prevent superclass
methods from being called on them when they're not looking

or

(2) Fixing the typeobject not to rely on that for its security --
by hiding the real dict more deeply somehow?

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg@cosc.canterbury.ac.nz	   +--------------------------------------+