overriding method that returns base class object
Aahz
aahz at pythoncraft.com
Mon Feb 16 19:20:29 EST 2004
In article <40315037$0$199$75868355 at news.frii.net>,
Stuart McGraw <smcg4191 at frii.RemoveThisToReply.com> wrote:
>
>Class A has a method A.a() that returns an A. I want a
>identical class but with an additional property .newprop
>and method .b() And I want .a() to return a B, not an A.
>
> class B (A):
> def __init__(self, *args, **kwds):
> A.__init__(self, *args, **kwds)
> self.newprop = 99
> def a(self):
> x = A.a(self) # x is an A
> x.__class__ = B
> return x # I want x to be a B, i.e have b() and .newprop.
> def b(self):
> ...something...
>
>Yes, I know this is bogus. But I am not sure what I should be doing.
>And to correct what I originally posted, A is implented in python
>(but I still can't change it for administrative reasons), but it's
>properties are declared with "__slots__ = [...]" if that makes a
>difference. This is all in Python 2.3.3.
class A:
def a(self):
return self.__class__()
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"Argue for your limitations, and sure enough they're yours." --Richard Bach
More information about the Python-list
mailing list