Language design

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Sep 11 19:40:35 EDT 2013


On Wed, 11 Sep 2013 22:41:50 +0200, Markus Rother wrote:

>     2. Reduce removed from standard library.  That is a big fail, in my
>     opinion.

And Guido's Time Machine strikes again!


py> from functools import reduce
py> reduce
<built-in function reduce>




[...]
>     4. As has been mentioned already, some built-in functions do magic
>     stuff behind the scenes:
> 
>     >>> () == []
>     False
> 
> 
>     But:
> 
> 
>     >>> bool(().__eq__([]))
>     True
> 
> 
>     Because:
> 
> 
>     >>> ().__eq__([])
>     NotImplemented
> 
> 
>     which yields True when cast to boolean. """

I don't see that this is a gotcha, let alone a design mistake. There's no 
reason to be calling __eq__ directly instead of == but if you do, you're 
responsible for handling the operator protocol yourself. Namely, if the 
operator special method returns NotImplemented, you're supposed to 
reverse the operands and try again.



-- 
Steven



More information about the Python-list mailing list