Re: (Newbie) Restricting inherited methods to operate on element from same subclass

2005-03-14 Thread andy2O
Bruno Desthuilliers wrote: > You've already got the technical answer. About a possible design flaw, > it would seem to me that restricting the join() operation on specific > subclasses breaks the LSP. OTOH, Python being dynamically typed, > inheritence is merely an implementation detail, so that m

Re: (Newbie) Restricting inherited methods to operate on element from same subclass

2005-03-11 Thread Bruno Desthuilliers
andy2o a écrit : Hi all, Sorry if the post's title is confusing... I'll explain: I have a class, called A say, and N>1 subclasses of A, called A1, A2, A3, ..., AN say. Instances of each subclass can sensibly be joined together with other instances of the *same subclass*. The syntax of the join me

Re: (Newbie) Restricting inherited methods to operate on element from same subclass

2005-03-11 Thread andy2O
>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!

Re: (Newbie) Restricting inherited methods to operate on element from same subclass

2005-03-11 Thread Duncan Booth
andy2o wrote: > But I want to raise an exception if my code finds: > > f = A1() > g = A2() > f.join(g) #should raise exception, as cannot join an > #instance of A1 to an instance of A2. > > How can I verify in a method defined in class A that the subclasses I > am joining are exactly

(Newbie) Restricting inherited methods to operate on element from same subclass

2005-03-11 Thread andy2o
Hi all, Sorry if the post's title is confusing... I'll explain: I have a class, called A say, and N>1 subclasses of A, called A1, A2, A3, ..., AN say. Instances of each subclass can sensibly be joined together with other instances of the *same subclass*. The syntax of the join method is identic