Operator commutativity
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Mon Sep 19 22:43:25 EDT 2011
On Mon, 19 Sep 2011 22:26:30 -0400, Roy Smith wrote:
> In article <4e77eae1$0$29978$c3e8da3$5496439d at news.astraweb.com>,
> Steven D'Aprano <steve+comp.lang.python at pearwood.info> 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 leading to some weird diagnostics.
"Weird"?
You've lived a sheltered life if you think a function being known under
two names is weird. Wait until you discover monkey-patching built-ins for
fun and profit!
--
Steven
More information about the Python-list
mailing list