On Wed, May 14, 2014 at 11:08 PM, Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> wrote: > One should code as if the next person who reads your program is an easily > upset psychotic axe-murderer who knows where you live. You wouldn't > condone writing y = x.__add__(1) instead of y = x + 1, you shouldn't > condone writing module.__setattr__ directly either.
Oddly enough, I was referencing that first half earlier this evening :) There's a difference between x.__add__(1) and x + 1, though. The latter might end up calling (1).__radd__(x), which (obviously) the first won't. I can imagine there might be some use-case where you specifically DON'T want the reflected method to be silently called (maybe for introspection or debugging??). But it falls under code smell, the sort of thing where you absolutely MUST have a comment - like where I have a call to set_foreground(bg), because that could so easily be an error, yet in this case isn't. ChrisA -- https://mail.python.org/mailman/listinfo/python-list