On 10/08/2014 03:46 PM, Terry Reedy wrote:
On 10/8/2014 5:49 PM, Ethan Furman wrote:
[redirecting back to the list]
I'm not sure what situation you would have to type them (as opposed to
simply a + b) that the operator module would help with.
unittest springs to mind:
self.assertRaises(TypeError, op.add, obj1, obj2)
Er, my point is, that is not a situation where you would be able to use
obj1.__add__ - you'd have to use the operator module *anyway*, and
therefore aren't using it just to get the convenience of a non-dunder
name.
self.assertRaises(TypeError, lambda x, y: x+y, obj1, obj2)
That works, but is a bit harder to type (given the import), more confusing to
read (the extra ',' that does *not*
delimit an argument) and adds an extra layer to the call stack with each call.
The extra layer *could* make a
difference in recursion.
Indeed, thanks for the corrections. I was merely replying to the "have to use the
operator module anyway" comment.
--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list