[plt-scheme] An Editors Tale

From: Daniel Silva (dansilva at lynx.dac.neu.edu)
Date: Mon Feb 9 04:00:40 EST 2004

On Fri, 2004-02-06 at 11:13, Joe Marshall wrote:
> Jeremy Hylton <jeremy at alum.mit.edu> writes:
> 
> > I'm assuming the analysis would just need to be conservative.  The
> > expression L[2] is equivalent to L.__getitem__(2).  You can't know, in
> > general, whether a method call will have a side-effect, but method calls
> > aren't a special case of the analysis.
> 
> You'd have to treat all indexing as calls to unknown functions.  You'd
> either have to do whole-world analysis or simply give up and say ``oh,
> you used an index, I have no clue what *that* might do.''
> 
> For something like __getitem__ where you are likely to simply be
> replacing the definition in one class, you could analyze that class to
> determine the effect, but if you start introducing methods `on the
> fly' by injecting them into instances via __setattr__, then knowing
> the value at one time says nothing about the value at another.

Why not abolish method rewriting and introduce mixins into Python?

Yet another example...

class C(object):
  def __init__(self, x):
    self.set_x(x)
    
  def get_x(self): return self.x
  def set_x(self, x): self.x = x

# Seems harmless enough.



myc = C(2)
print myc.x
print myc.get_x()

#  Still ok.



def oops(obj, attr):
 while 1: pass

type.__setattr__(C, "__getattribute__", oops)

print myc.get_x()
print myc.x

# oops...
# oh well, at least it wasn't "import os; os.system('rm -rf /')"

# Daniel



Posted on the users mailing list.