[Python-Dev] Evil setattr hack
Mon, 14 Apr 2003 07:33:25 +0100
Greg Ewing <email@example.com> writes:
Er, this was me.
>> 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
> (2) Fixing the typeobject not to rely on that for its security --
> by hiding the real dict more deeply somehow?
Yeah, another option would be to make _PyObject_GetDictPtr respect
__dict__ descriptors. But that's probably the Wrong Answer, too.
Maybe just PyObject_GenericSetAttr should do that -- call
PyObject_GetAttr(ob, '__dict__'), basically.
We did requirements and task analysis, iterative design, and user
testing. You'd almost think programming languages were an interface
between people and computers. -- Steven Pemberton
(one of the designers of Python's direct ancestor ABC)