Re: Down casting Python objects

2010-03-10 Thread Steve Holden
Andrey Fedorov wrote: > On Wed, Mar 10, 2010 at 12:24 AM, Rami Chowdhury > mailto:rami.chowdh...@gmail.com>> wrote: > > Could you tell us *why* you need to down-cast x? Explicit > type-casting is usually unnecessary in Python... > > > Sure! It's related to the longer question I unwisely

Re: Down casting Python objects

2010-03-10 Thread Andrey Fedorov
On Wed, Mar 10, 2010 at 12:24 AM, Rami Chowdhury wrote: > Could you tell us *why* you need to down-cast x? Explicit type-casting is > usually unnecessary in Python... Sure! It's related to the longer question I unwisely asked during PyCon [1] (when no one had time to read it, I suppose). I hav

Re: Down casting Python objects

2010-03-09 Thread Gabriel Genellina
En Tue, 09 Mar 2010 18:26:52 -0300, Andrey Fedorov escribió: So I have `x', a instance of class `Foo'. I also have class `Bar', a class extending `Foo' with a couple of methods. I'd like to "down cast" x as efficiently as possible. Is it OK to just set `x.__class__ = Bar' and expect thin

Re: Down casting Python objects

2010-03-09 Thread Rami Chowdhury
On Mar 9, 2010, at 13:26 , Andrey Fedorov wrote: > So I have `x', a instance of class `Foo'. I also have class `Bar', a class > extending `Foo' with a couple of methods. I'd like to "down cast" x as > efficiently as possible. Is it OK to just set `x.__class__ = Bar' and expect > things to work

Down casting Python objects

2010-03-09 Thread Andrey Fedorov
So I have `x', a instance of class `Foo'. I also have class `Bar', a class extending `Foo' with a couple of methods. I'd like to "down cast" x as efficiently as possible. Is it OK to just set `x.__class__ = Bar' and expect things to work OK in all major versions of CPython? -- http://mail.python.o