From: Vladimir.Marangozov at inrialpes.fr (Vladimir Marangozov)
Date: Thu, 08 Apr 1999 16:51:42 +0200
Subject: Chaning instance methods
References: <370C2904.A6F4BD54@inrialpes.fr> <000801be8188$b59aa9a0$749e2299@tim>
Message-ID: <370CC27E.ED2D0D59@inrialpes.fr>
X-UID: 1292                                                  

Tim Peters wrote:
> 
> [me, on f being an instance of Foo, becoming an instance of Bar,
>  the latter being derived directly from Foo]
> > ...
> 
> When I signed my exposition of instance-method trickery "subclassing-is-
> a-lot-easier-ly y'rs", I had exactly this in mind:
> 
> class Bar(Foo):
>     def m(self):
>         print "m2"
> 
> f = Bar()
>

Careful!
We'll eventually see what you had exactly in mind if you change the last
line from

(1) f = Bar()

to

(2) f.__class__ = Bar

While (1) resets f's internal state and makes a brand new instance,
(2) preserves that state (which reflects f's past existence as an
instance of Foo) by changing only its interface to that of Bar
"on the fly". The difference is quite fundamental.

We all knew that you meant (2) in your sig, but making it slightly
more explicit does not hurt :-)

-- 
       Vladimir MARANGOZOV          | Vladimir.Marangozov at inrialpes.fr
http://sirac.inrialpes.fr/~marangoz | tel:(+33-4)76615277 fax:76615252




