Re: class inheritance

2010-12-23 Thread JLundell
That's nice, Ethan, especially in that it saves having to explicitly find and list all the methods being covered. It's perhaps not quite so critical for a Fraction-based class, since the set of methods to be covered is fairly well contained, but that's not always going to be the case. The appro

Re: class inheritance

2010-12-17 Thread JLundell
On Saturday, March 13, 2010 9:03:36 AM UTC-8, Jonathan Lundell wrote: > I've got a subclass of fractions.Fraction called Value; it's a mostly > trivial class, except that it overrides __eq__ to mean 'nearly equal'. > However, since Fraction's operations result in a Fraction, not a > Value, I end up

Re: class inheritance

2010-03-18 Thread JLundell
On Mar 17, 5:12 pm, Steven D'Aprano wrote: > On Mon, 15 Mar 2010 16:34:35 -0700,JLundellwrote: > > It's also unfortunate that Python doesn't have an approximately-equal > > operator; it'd come in handy for floating-point applications while > > preserving hash. If only there were a ~= or ≈ operator

Re: class inheritance

2010-03-16 Thread JLundell
On Mar 16, 8:06 am, Robert Kern wrote: > On 2010-03-16 07:35 AM, Dave Angel wrote: > > > > > > > > > Carl Banks wrote: > >> On Mar 15, 4:34 pm, JLundell wrote: > >>> It's also unfortunate that Python doesn't have an approximatel

Re: class inheritance

2010-03-15 Thread JLundell
On Mar 13, 1:26 pm, Carl Banks wrote: > It's a tad unfortunately Python doesn't make this easier.  If I had to > do it more than once I'd probably write a mixin to do it: > > class ArithmeticSelfCastMixin(object): >     def __add__(self,other): >         return > self.__class__(super(ArithmeticSel

Re: class inheritance

2010-03-13 Thread JLundell
On Mar 13, 9:37 am, Jack Diederich wrote: > If Fraction.__add__ returns a new object but the subclass Value is > compatible (as I would except since it is a sublcass) then just change > all references in Franction.__add__ to be more generic, ex/ > > class Franction(): >   def __add__(self, other):

class inheritance

2010-03-13 Thread JLundell
I've got a subclass of fractions.Fraction called Value; it's a mostly trivial class, except that it overrides __eq__ to mean 'nearly equal'. However, since Fraction's operations result in a Fraction, not a Value, I end up with stuff like this: x = Value(1) + Value(2) where x is now a Fraction, no