Steven D'Aprano wrote:
After playing around with various combinations of C1, C2, D1 and D2, it
seems to me that the rule is:
If the right-hand argument is a subclass of the left-hand argument, AND also
defines __radd__ directly rather than inheriting it, then its __radd__
method is called before
Mark Dickinson wrote:
On Sep 21, 2:07 am, Steven D'Aprano wrote:
After playing around with various combinations of C1, C2, D1 and D2, it
seems to me that the rule is:
If the right-hand argument is a subclass of the left-hand argument, AND also
defines __radd__ directly rather than inheriting i
On Sep 21, 2:07 am, Steven D'Aprano wrote:
> After playing around with various combinations of C1, C2, D1 and D2, it
> seems to me that the rule is:
>
> If the right-hand argument is a subclass of the left-hand argument, AND also
> defines __radd__ directly rather than inheriting it, then its __ra
On Wed, Sep 21, 2011 at 11:07 AM, Steven D'Aprano
wrote:
> If the right-hand argument is a subclass of the left-hand argument, AND also
> defines __radd__ directly rather than inheriting it, then its __radd__
> method is called before the left-hand argument's __add__ method.
>
> which strikes me a
Ethan Furman wrote:
> Peter Pearson wrote:
>> On Mon, 19 Sep 2011 05:48:07 -0700, Ethan Furman
>> wrote:
>> [snip]
>>> Also, if the right-hand operand is a subclass of the left-hand operand
>>> then Python will try right-hand_operand.__radd__ first.
>>
>> I don't think it works that way for me:
Peter Pearson wrote:
On Mon, 19 Sep 2011 05:48:07 -0700, Ethan Furman wrote:
[snip]
Also, if the right-hand operand is a subclass of the left-hand operand
then Python will try right-hand_operand.__radd__ first.
I don't think it works that way for me:
Python 2.6.5 (r265:79063, Apr 16 2010, 13
On Mon, 19 Sep 2011 05:48:07 -0700, Ethan Furman wrote:
[snip]
> Also, if the right-hand operand is a subclass of the left-hand operand
> then Python will try right-hand_operand.__radd__ first.
I don't think it works that way for me:
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
>>> class C
On Mon, Sep 19, 2011 at 10:26:30PM -0400, Roy Smith wrote:
> In article <4e77eae1$0$29978$c3e8da3$54964...@news.astraweb.com>,
> Steven D'Aprano wrote:
>
> > Westley Mart??nez wrote:
> >
> > > def __radd__(self, other):
> > > return self.__add__(self, other)
> >
> > Which, inside a class,
In article <4e77eae1$0$29978$c3e8da3$54964...@news.astraweb.com>,
Steven D'Aprano wrote:
> Westley MartÃnez wrote:
>
> > def __radd__(self, other):
> > return self.__add__(self, other)
>
> Which, inside a class, can be simplified to:
>
> __radd__ = __add__
Ooh, I could see that lead
Westley Martínez wrote:
> def __radd__(self, other):
> return self.__add__(self, other)
Which, inside a class, can be simplified to:
__radd__ = __add__
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Mon, Sep 19, 2011 at 01:11:51PM +0200, Henrik Faber wrote:
> Hi there,
>
> when I have a python class X which overloads an operator, I can use that
> operator to do any operation for example with an integer
>
> y = X() + 123
>
> however, say I want the "+" operator to be commutative. Then
>
On 9/19/2011 8:48 AM, Ethan Furman wrote:
Roy Smith wrote:
__radd__() only solves the problem if the left-hand operand has no
__add__() method itself.
Only true if the left-hand operand is so ill-behaved it doesn't check to
see if it makes sense to add itself to the right-hand operand. If it
Roy Smith wrote:
In article ,
Henrik Faber wrote:
On 19.09.2011 13:23, Paul Rudin wrote:
Henrik Faber writes:
How can I make this commutative?
Incidentally - this isn't really about commutativity at all - the
question is how can you define both left and right versions of add,
irrespectiv
In article ,
Henrik Faber wrote:
> On 19.09.2011 13:23, Paul Rudin wrote:
> > Henrik Faber writes:
> >
> >> How can I make this commutative?
> >
> > Incidentally - this isn't really about commutativity at all - the
> > question is how can you define both left and right versions of add,
> > ir
On 19.09.2011 13:23, Paul Rudin wrote:
> Henrik Faber writes:
>
>> How can I make this commutative?
>
> Incidentally - this isn't really about commutativity at all - the
> question is how can you define both left and right versions of add,
> irrespective of whether they yield the same result.
R
Henrik Faber wrote:
> Hi there,
>
> when I have a python class X which overloads an operator, I can use that
> operator to do any operation for example with an integer
>
> y = X() + 123
>
> however, say I want the "+" operator to be commutative. Then
>
> y = 123 + X()
>
> should have the sam
Henrik Faber writes:
> How can I make this commutative?
Incidentally - this isn't really about commutativity at all - the
question is how can you define both left and right versions of add,
irrespective of whether they yield the same result.
I think __radd__ is what you're after.
--
http://ma
On 19 September 2011 12:11, Henrik Faber wrote:
> Hi there,
>
> when I have a python class X which overloads an operator, I can use that
> operator to do any operation for example with an integer
>
> y = X() + 123
>
> however, say I want the "+" operator to be commutative. Then
>
> y = 123 + X()
>
Hi there,
when I have a python class X which overloads an operator, I can use that
operator to do any operation for example with an integer
y = X() + 123
however, say I want the "+" operator to be commutative. Then
y = 123 + X()
should have the same result. However, since it does not call __ad
19 matches
Mail list logo