Re: (Newbie) Restricting inherited methods to operate on element from same subclass
andy2O_at_hotmail.com
Date: 03/11/05
- Next message: Tim N. van der Leeuw: "Re: RELEASED Python 2.4.1, release candidate 1"
- Previous message: Diez B. Roggisch: "Re: Confused with classmethods"
- In reply to: Duncan Booth: "Re: (Newbie) Restricting inherited methods to operate on element from same subclass"
- Next in thread: Bruno Desthuilliers: "Re: (Newbie) Restricting inherited methods to operate on element from same subclass"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 11 Mar 2005 05:26:34 -0800
>Assuming that A is a new-style class then if they have to be
>exactly the same type compare the types
Ah-ha! I didn't know that.
>if the 'other' value can be a subclass of self:
>
> def join(self, other):
> if not isinstance(other, type(self)):
> raise whatever
Simple and neat!
>If A is an old-style class then you would have to compare
>the __class__ attribute: self.__class__ != other.__class__
That answered my question perfectly. I'll read up on the new style
classes and pick whichever of your solutions fits best.
Many thanks,
Andy.
- Next message: Tim N. van der Leeuw: "Re: RELEASED Python 2.4.1, release candidate 1"
- Previous message: Diez B. Roggisch: "Re: Confused with classmethods"
- In reply to: Duncan Booth: "Re: (Newbie) Restricting inherited methods to operate on element from same subclass"
- Next in thread: Bruno Desthuilliers: "Re: (Newbie) Restricting inherited methods to operate on element from same subclass"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]